Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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:

#!/bin/bash
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
1  
+(a|b) shouldn't be 'quoted' in your script; that suppresses evaluation. –  mrb Aug 15 '12 at 13:28

1 Answer 1

up vote 5 down vote accepted

You have to turn on extglob:

#!/bin/bash
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

 
discard

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.