python_reference/useful_scripts/prepend_python_shebang.sh

22 lines
534 B
Bash
Raw Normal View History

#!/usr/bin/env bash
2014-05-21 21:17:45 +00:00
# Sebastian Raschka 05/21/2014
# Shell script that prepends a Python shebang
2014-05-21 23:20:06 +00:00
# '#!/usr/bin/env python' to all
2014-05-21 21:17:45 +00:00
# Python script files in the current directory
# so that script files can be executed via
# >> myscript.py
# instead of
# >> python myscript.py
2014-05-21 23:20:06 +00:00
# prepends '#!/usr/bin/env python' to all .py files
2014-05-21 21:44:05 +00:00
2014-05-21 21:17:45 +00:00
find ./ -maxdepth 1 -name "*.py" -exec sed -i.bak '1i\
2014-05-21 23:20:06 +00:00
#!/usr/bin/env python
2014-05-21 21:17:45 +00:00
' {} \;
2014-05-21 21:26:28 +00:00
# removes temporary files
find . -name "*.bak" -exec rm -rf {} \;
# makes Python scripts executable
2014-05-21 23:20:06 +00:00
chmod ug+x *.py