Created
August 26, 2014 12:18
-
-
Save proxypoke/d32a99483533d1ca664d to your computer and use it in GitHub Desktop.
Fix broken python code that makes assumptions about /usr/bin/python.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Fix all shebangs of files in a directory which do not explicitly state the | |
# major version number of the Python interpreter, ie refer to /usr/bin/python | |
# and assume that it is 2.x (or 3.x, but most Python 3 projects already use | |
# /usr/bin/env python3). | |
echo "Explicit is better than implicit! | |
This will fix all shebangs referring to /usr/bin/python | |
in all files below the current directory. | |
THIS OPERATION IS RECURSIVE AND DESTRUCTIVE! USE A VCS! | |
" | |
read -p "Proceed? (y/n) " answer | |
case $answer in | |
[yY]) | |
echo -n "Fixing shebangs..." | |
grep -Rl '#!/usr/bin/python$' |\ | |
xargs sed -i 's#\(/usr/bin/\)python#\1env python2#' | |
echo "done" | |
exit 0 | |
;; | |
*) | |
echo "Aborting." | |
exit 1 | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
don't you mean
grep -Rl '#!/usr/bin/python$' * |\ xargs sed -i 's#\(/usr/bin/\)python#\1env python2#'
?