diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2017-04-05 20:06:39 +1200 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2017-04-05 20:46:47 +1200 |
commit | c8ab406749124d2e762ad5cf53963070113afd0f (patch) | |
tree | 54c9721a06957ebe7098a211eea803b0230c0f5d /bin/shb.sh | |
parent | Handle POSIX correctness in ~/.bash_profile (diff) | |
download | dotfiles-c8ab406749124d2e762ad5cf53963070113afd0f.tar.gz dotfiles-c8ab406749124d2e762ad5cf53963070113afd0f.zip |
Apply runtime shebanging to POSIX shell
Diffstat (limited to 'bin/shb.sh')
-rw-r--r-- | bin/shb.sh | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/bin/shb.sh b/bin/shb.sh new file mode 100644 index 00000000..7d31876d --- /dev/null +++ b/bin/shb.sh @@ -0,0 +1,26 @@ +# Use PATH to build a shebang for a script given on stdin +self=shb + +# Need at least two arguments +if [ "$#" -lt 1 ] ; then + printf >&2 '%s: Need interpreter command\n' "$self" + exit 1 +fi + +# First argument is the name of the interpreter +intn=$1 +shift + +# Try and find the path to the interpreter command, bail out if we can't +if ! intp=$(command -v "$intn" 2>/dev/null) ; then + printf >&2 '%s: %s: command not found\n' "$self" "$intn" + exit 1 +fi + +# Set the positional parameters to the path and any remaining arguments, and +# squash them together for the shebang line +set -- "$intp" "$@" +printf '#!%s\n' "$*" + +# Emit the rest of the input +cat |