2

How to write a cycle pro all files *.py except a.py?

for i in *.py && !(a.py); do 
    python3 $i
done
0
4

With extended globs (shopt extglob set in Bash), !(a).py should match all filenames ending in .py, except for a.py:

$ shopt -s extglob
$ ls 
a.py  bar.py  foo.py  foo.txt
$ echo !(a).py
bar.py foo.py

But you could also just exclude that one file manually with a test, this wouldn't need any Bash-specific features:

for f in ./*.py; do
    [ "$f" = a.py ] && continue
    python "$f"
done
1
  • Thank you very much
    – Archie
    Oct 19 '19 at 12:05

Not the answer you're looking for? Browse other questions tagged or ask your own question.