Daniel@0: #!/bin/sh Daniel@0: if [ $# -lt 3 ]; then Daniel@0: echo 'bufs ...' Daniel@0: echo Daniel@0: echo 'Apply command to arguments but buffering the nth argument' Daniel@0: echo 'of command (ie (n+1)th argument of strm) into a temporary file.' Daniel@0: echo 'This means that the nth argument can safely be replaced with' Daniel@0: echo 'a bash process redirection.' Daniel@0: exit 1 Daniel@0: fi Daniel@0: set -o nounset Daniel@0: set -e Daniel@0: Daniel@0: function str1 { Daniel@0: cmd="$1" Daniel@0: arg1="$2" Daniel@0: tmp=`mktemp -t strXXX` Daniel@0: # echo created $tmp 1>&2 Daniel@0: trap "rm -f $tmp; exit" INT KILL EXIT Daniel@0: shift 2 Daniel@0: (cat "$arg1" > $tmp) && $cmd $tmp "$@" Daniel@0: } Daniel@0: Daniel@0: function str { Daniel@0: pos=$1 Daniel@0: shift 1 Daniel@0: if [ $pos -eq 1 ]; then Daniel@0: str1 "$@" Daniel@0: else Daniel@0: cmd="$1 $2" Daniel@0: shift 2 Daniel@0: str $(($pos-1)) "$cmd" "$@" Daniel@0: fi Daniel@0: } Daniel@0: str "$@"