Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

When, in my terminal, I type

cat ~/my/+(a|b)/doc

It reads ok from both ~/my/a/doc and ~/my/b/doc, but when I put that command in a bash script:

cat ~/my/'+(a|b)'/doc

I get the error:

cat: ~/my/+(a|b)/doc: No such file or directory

Is it not possible to use extended globbing inside a bash script?

share|improve this question
+(a|b) shouldn't be 'quoted' in your script; that suppresses evaluation. – mrb Aug 15 '12 at 13:28
up vote 6 down vote accepted

You have to turn on extglob:

shopt -s extglob
cat ~/my/+(a|b)/doc

+() is an extended pattern, is only recognized when extglob is enabled. By default extglob is on in interactive shells and off in non-interactive shells.

share|improve this answer
right on the spot! thanks a lot @manatwork :) – François ッ Vespa ت Aug 15 '12 at 13:29

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.