^ is a glob operator available when
EXTENDED_GLOB is set, matching anything except the following pattern.
The parentheses group a pattern; this is useful in particular with disjunctions (
|) where parentheses are required so that the disjunction isn’t interpreted as a pipe.
^(*.c||*.md) means “anything except files matching
*.c, or files with an empty name, or files matching
*.md”; the empty name is useless, so you should use
|. You could also write it
^*.(c|md) to avoid repeating the
You should also use the
-- option delimiter for
ls as otherwise if any of the file names started with
-, they'd be treated as options by
If you don't intend
ls to list the contents of those files resulting from that glob expansion that happen to be of type directory, you should use the
-d option. Or just use the
print builtin to print those file names;
ls would only be useful with options like
-l to get metadata information from those files.
ls -ld -- ^*.(md|c)
print -rC1 -- ^*.(md|c)(N)
Here with the file names
N glob qualifier for
NULL_GLOB to avoid an error if no matching file is found (and get no output from