python_reference/useful_scripts/prepend_python_shebang.sh

22 lines
534 B
Bash
Raw Normal View History

#!/usr/bin/env bash
2014-05-21 17:17:45 -04:00
# Sebastian Raschka 05/21/2014
# Shell script that prepends a Python shebang
2014-05-21 19:20:06 -04:00
# '#!/usr/bin/env python' to all
2014-05-21 17:17:45 -04: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 19:20:06 -04:00
# prepends '#!/usr/bin/env python' to all .py files
2014-05-21 17:44:05 -04:00
2014-05-21 17:17:45 -04:00
find ./ -maxdepth 1 -name "*.py" -exec sed -i.bak '1i\
2014-05-21 19:20:06 -04:00
#!/usr/bin/env python
2014-05-21 17:17:45 -04:00
' {} \;
2014-05-21 17:26:28 -04:00
# removes temporary files
find . -name "*.bak" -exec rm -rf {} \;
# makes Python scripts executable
2014-05-21 19:20:06 -04:00
chmod ug+x *.py