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?
Best Answer
You have to turn on
extglob
:+()
is an extended pattern, is only recognized whenextglob
is enabled. By defaultextglob
is on in interactive shells and off in non-interactive shells.