diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2016-08-02 19:23:52 +1200 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2016-08-02 19:24:20 +1200 |
commit | 02673c20da7ffe3d0a4aded934ae479ae5280781 (patch) | |
tree | 8958da26a40ca735a6f090161bb6b8f82303f969 /bin/shb | |
parent | sls(1) bail if no defaults and no arguments (diff) | |
download | dotfiles-02673c20da7ffe3d0a4aded934ae479ae5280781.tar.gz dotfiles-02673c20da7ffe3d0a4aded934ae479ae5280781.zip |
Add shb(1)
Diffstat (limited to 'bin/shb')
-rwxr-xr-x | bin/shb | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/bin/shb b/bin/shb new file mode 100755 index 00000000..743e5b75 --- /dev/null +++ b/bin/shb @@ -0,0 +1,28 @@ +#!/bin/sh +# Use PATH to build a shebang for a script given on stdin +self=shb + +# Need at least two arguments +if [ "$#" -lt 2 ] ; then + printf >&2 '%s: Need input file and command\n' "$self" + exit 1 +fi + +# First argument is the script (might be - for stdin), second argument is the +# name of the interpreter +scr=$1 intn=$2 +shift 2 + +# Try and find the path to the interpreter command, bail out if we can't +if ! intp=$(command -v "$intn") ; 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 -- "$scr" |