From 9d6199c5dc0911a5595e5f225ad909845ed8cc17 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Fri, 24 Mar 2017 09:11:27 +1300 Subject: Change shb(1) to read stdin by default This is clearer. --- Makefile | 8 ++++---- bin/shb | 13 ++++++------- man/man1/shb.1df | 16 ++++++---------- 3 files changed, 16 insertions(+), 21 deletions(-) diff --git a/Makefile b/Makefile index 71a5ceeb..fd3c9931 100644 --- a/Makefile +++ b/Makefile @@ -148,19 +148,19 @@ tmux/tmux.conf: tmux/tmux.conf.m4 tmux/tmux.conf.m4 > $@ .awk: - bin/shb $< awk -f > $@ + bin/shb awk -f < $< > $@ chmod +x -- $@ .bash: - bin/shb $< bash > $@ + bin/shb bash < $< > $@ chmod +x -- $@ .pl: - bin/shb $< perl > $@ + bin/shb perl < $< > $@ chmod +x -- $@ .sed: - bin/shb $< sed -f > $@ + bin/shb sed -f < $< > $@ chmod +x -- $@ install: install-bash \ diff --git a/bin/shb b/bin/shb index 49894b0f..72ac818b 100755 --- a/bin/shb +++ b/bin/shb @@ -3,15 +3,14 @@ self=shb # Need at least two arguments -if [ "$#" -lt 2 ] ; then - printf >&2 '%s: Need input file and command\n' "$self" +if [ "$#" -lt 1 ] ; then + printf >&2 '%s: Need interpreter 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 +# 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 @@ -25,4 +24,4 @@ set -- "$intp" "$@" printf '#!%s\n' "$*" # Emit the rest of the input -cat -- "$scr" +cat diff --git a/man/man1/shb.1df b/man/man1/shb.1df index 1970dbde..a1cb884a 100644 --- a/man/man1/shb.1df +++ b/man/man1/shb.1df @@ -4,20 +4,16 @@ \- insert a shebang line above a file .SH SYNOPSIS .B shb -script bash +bash < foo.bash > foo .br +cat *.sed | .B shb -script sed -f -.br -command | -.B shb -- awk -f +sed -f > sedbatch .SH DESCRIPTION .B shb -searches the system paths to find a suitable program with the name given in the -second argument, forms a "shebang" line from it and any arguments beyond the -second, and then emits the contents of the first argument ('-' can be used for -stdin). +searches the system paths to find a suitable program with the name given in its +first argument, forms a "shebang" line from it and any remaining arguments, and +then emits the contents of stdin. .P This is intended as a minimal way to make portable shebang lines for Makefiles or other building or installation frameworks, handling subtleties like sed(1) -- cgit v1.2.3