I have a bunch of very small python scripts that I want to run from the command line. Here is one such example:
import os
for f in os.listdir():
if not os.path.isdir(f) and f.endswith('.c'):
dir=f[:-2]
os.makedirs(dir)
os.rename( f, dir + '/' + f )
I am abundantly aware that I could save this as a python script (e.g. renamer.py) and run the script like this:
python renamer.py
However, in compiling a library, I have a lot of these small scripts, and would just like to concatenate these into a single shell script. I just can't figure out the syntax. I thought that the shell script should look like this:
#!/usr/bin/env bash
python -c/
"import os;"/
"for f in os.listdir():;"/
" if not os.path.isdir(f) and f.endswith('.c'):;"/
" dir=f[:-2];"/
" os.makedirs(dir);"/
" os.rename( f, dir + '/' + f );"
But when I run this I get the error:
File "<string>", line 1
/
^
SyntaxError: invalid syntax
./py_test.sh: line 4: import os;/: No such file or directory
./py_test.sh: line 5: for f in os.listdir():;/: No such file or directory
./py_test.sh: line 6: if not os.path.isdir(f) and f.endswith('.c'):;/: No such file or directory
./py_test.sh: line 7: dir=f[:-2];/: No such file or directory
./py_test.sh: line 8: os.makedirs(dir);/: No such file or directory
./py_test.sh: line 9: os.rename( f, dir + '/' + f );: No such file or directory
What am I missing here?