8 chshebang - Change a script's default interpreter
23 echo "Usage: $0 [-h|--help] [-f|--force] [-i|--insert] [-d|--dummy] <INTERPRETER> <FILES> ...
24 -f force replace 1st line with INTERPRETER, even if it does not start \`#!' signature
25 -i insert, instead of replace
26 -d disable intelligent path preparation
27 INTERPRETER basename or full path of new interpreter, leading \`#!' signature is implicite
28 examplpes: /usr/bin/awk, bash, #!/bin/sh
29 FILES files to modify"
37 -*) echo "Unknown option: $1" >&2
50 if [ $dummy = 0 ]; then
51 if [ "${shebang:0:2}" != '#!' ]; then
52 if [ "${shebang:0:1}" != '/' ]; then
57 echo "Command not found: $shebang" >&2
65 # escape sed(1) meta chars in this order: \ , &
66 shebang
=${shebang//\\/\\\\}
67 shebang
=${shebang//,/\\,}
68 shebang
=${shebang//&/\\&}
70 if [ $insert -eq 1 ]; then
72 sed -n "1i$shebang${NL}p" -i "$file"
75 elif [ $force -eq 1 ]; then
77 sed -n "1s,^.*\$,$shebang,;p" -i "$file"
82 sed -n "1s,^#!/.*\$,$shebang,;p" -i "$file"