Bash Extended Globbing gives syntax error
Solution 1:
Because extglob doesn't work that way. You must put one of the modifier characters at the beginning of your pattern list ((txt|doc)
in this case), as follows (from man bash
):
?(pattern-list)
Matches zero or one occurrence of the given patterns
*(pattern-list)
Matches zero or more occurrences of the given patterns
+(pattern-list)
Matches one or more occurrences of the given patterns
@(pattern-list)
Matches one of the given patterns
!(pattern-list)
Matches anything except one of the given patterns
Specifically, ls *.*(txt|doc)
produces the behaviour I am guessing you want.
Solution 2:
You can do this without the extended globbing using brace expansion: ls *.{txt,doc}