How to iterate over files in the current directory and exclude some files having specific name patters? The solution must be POSIX compatible.
Assume the files to exclude follow the patterns: test[0-9].txt and work-.* (using regex).
The code I have so far:
for file in *
do
if test "$file" != "test[0-9].txt" -o "$file" != "work-.*"
then
echo "$file"
fi
done
At the moment the output is all files in the working directory. I'm pretty sure pattern matching in test is incorrect, but how can I fix it?
ksh
globbing:printf '%s\n' !(test[0-9].txt|work-.*)
(untested) – Kusalananda Apr 01 '21 at 11:40