2

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

for i in *.py && !(a.py); do 
    python3 $i
done
Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
Archie
  • 45
  • 5

1 Answers1

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
ilkkachu
  • 133,243
  • 15
  • 236
  • 397