diff --git a/README.md b/README.md index 26facab..775d2d4 100755 --- a/README.md +++ b/README.md @@ -38,6 +38,8 @@ Useful functions, tutorials, and other Python-related things - Happy Mother's Day [[IPython nb]](http://nbviewer.ipython.org/github/rasbt/python_reference/blob/master/funstuff/happy_mothers_day.ipynb?create=1) -**// useful snippets** +**// useful scripts snippets** + +- [Shell script](./useful_scripts/prepend_python_shebang.sh) for prepending Python-shebangs to all .py files in a current directory. - convert 'tab-delimited' to 'comma-separated' CSV files [[IPython nb]](http://nbviewer.ipython.org/github/rasbt/python_reference/blob/master/useful_scripts/fix_tab_csv.ipynb?create=1) diff --git a/useful_scripts/prepend_python_shebang.sh b/useful_scripts/prepend_python_shebang.sh new file mode 100644 index 0000000..cff7677 --- /dev/null +++ b/useful_scripts/prepend_python_shebang.sh @@ -0,0 +1,14 @@ +# Sebastian Raschka 05/21/2014 +# Shell script that prepends a Python shebang +# `!#/usr/bin/python` to all +# Python script files in the current directory +# so that script files can be executed via +# >> myscript.py +# instead of +# >> python myscript.py + +find ./ -maxdepth 1 -name "*.py" -exec sed -i.bak '1i\ +!#/usr/bin/python +' {} \; + +find . -name "*.bak" -exec rm -rf {} \; \ No newline at end of file