In zsh
:
files=($PWD/*.(abc|ABC|DEF)(N))
print -rC1 -- $files # print raw, on one column.
(with the (N)
qualifier to apply nullglob
to that glob, to that $files
become an empty list of the pattern doesn't match any file instead of reporting an error).
For files other than .sh
and .jkl
:
set -o extendedglob # needed for the ^ negation operator
files=($PWD/^*.(sh|jkl)(N))
For case insensitive matching (.ABC
/.abc
/.Abc
...):
set -o extendedglob
files=($PWD/*.(#i)abc(N))
Your:
FILES="$PWD/*"
echo $FILES
is wrong on several accounts:
FILES="$PWD/*"
doesn't store the list of files in the $FILE
variable. That's a scalar assignment, which can only ever store one value. Instead it stores in $FILES
the contents of $PWD
followed by /*
literally.
In, echo $FILES
as $FILES
is not quoted, in bash
(but not zsh
), the expansion of $FILES
is subject to split+glob. And it's at that point, and assuming that $FILES
contains none of the characters of $IFS
(which would trigger the split part), and that $PWD
doesn't contain wildcard characters (that would also trigger the glob part) that the value is expanded to the list of matching files.
In zsh
, split+glob is not done implicitly upon parameter expansion, you need to request them explicitly ($=FILES
for splitting, $~FILES
for globbing, $=~FILES
for both).
Then using echo
to output arbitrary data is wrong as echo
does extra processing by default (in zsh
, you could use echo -E - $files
or print -r -- $files
though).
zsh
as its default shell. I have therefore tagged your question withbash
(for Ubuntu) andzsh
. – terdon Oct 03 '20 at 12:53zsh
is the Catalina default shell:echo $SHELL
` – gatorback Oct 03 '20 at 17:32#!/bin/bash
) and don't override it by running the script with a command likesh scriptname
. – Gordon Davisson Oct 03 '20 at 17:40