Skip to content

Instantly share code, notes, and snippets.

@kkew3
Last active December 19, 2018 21:56
Show Gist options
  • Save kkew3/14a0cbea902e21ef85b60fd13b36c351 to your computer and use it in GitHub Desktop.
Save kkew3/14a0cbea902e21ef85b60fd13b36c351 to your computer and use it in GitHub Desktop.
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$$'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment