kkew3
12/19/2018 - 9:50 PM

Ensure that bash shebang exists at the head of a script

Ensure that bash shebang exists at the head of a script

/^ *$/d
/^#[^!]/d
1,/^#!\(\/bin\/\|\/usr\/bin\/env \)\(ba\)\?sh$/p
/^#!\(\/bin\/\|\/usr\/bin\/env \)\(ba\)\?sh$/q
# returns none-zero when there's no shebang in file "$1"
test -f "$1"
# the `awk '{print $1}' is used to be compatible with BSD wc, which prepend a TAB character
test "$$(sed -n -f _check_shebang_shell.sed "$1" | wc -l | awk '{print $1}')" = 1
sed 'sed -n -f _check_shebang_shell.sed "$1" | tail -n1 | grep -q '^#!\(\/bin\/\|\/usr\/bin\/env \)\(ba\)\?sh$$'