Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 136989
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T07:02:08+00:00 2026-05-11T07:02:08+00:00

In addition to the basic * , ? and […] patterns, the Bash shell

  • 0

In addition to the basic *, ? and [...] patterns, the Bash shell provides extended pattern matching operators like !(pattern-list) (‘match all except one of the given patterns’). The extglob shell option needs to be set to use them. An example:

~$ mkdir test ; cd test ; touch file1 file2 file3 ~/test$ echo * file1 file2 file3 ~/test$ shopt -s extglob  # make sure extglob is set ~/test$ echo !(file2) file1 file3 

If I pass a shell expression to a program which executes it in a sub-shell, the operator causes an error. Here’s a test which runs a sub-shell directly (here I’m executing from another directory to make sure expansion doesn’t happen prematurely):

~/test$ cd .. ~$ bash -c 'cd test ; echo *' file1 file2 file3 ~$ bash -c 'cd test ; echo !(file2)'  # expected output: file1 file3 bash: -c: line 0: syntax error near unexpected token `(' bash: -c: line 0: `cd test ; echo !(file2)' 

I’ve tried all kinds of escaping, but nothing I’ve come up with has worked correctly. I also suspected extglob is not set in a sub-shell, but that’s not the case:

~$ bash -c 'shopt -s extglob ; cd test ; echo !(file2)' bash: -c: line 0: syntax error near unexpected token `(' bash: -c: line 0: `cd test ; echo !(file2)' 

Any solution appreciated!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T07:02:09+00:00Added an answer on May 11, 2026 at 7:02 am
     $ bash -O extglob -c 'echo !(file2)' file1 file3 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to implement basic arithmetic (at least addition) in C# generics, like
In addition to this question: iPhone network performance , I would like to know
I have basic idea about running PHP in different configurations like mod_php, cgi, FastCGI,
I'm trying to implement a basic addition program in node.js that accepts 2 numbers
I'm planning to write a simple interpreter ( like TI-BASIC language for TI-89 )
I'm attempting to create an interactive number line to aid in basic addition/subtraction learning
In addition to my previous question , another problem appeared and I decided to
Is addition(+) operation more complex than comparison operation (>), both in integer as well
In addition to the datastore for your specific site, can you also share one
In addition to jquery plugin options, I want to override those values with html5

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.