Mercurial > hg > dml-open-cliopatria
diff cpack/dml/scripts/compression/bufs @ 0:718306e29690 tip
commiting public release
author | Daniel Wolff |
---|---|
date | Tue, 09 Feb 2016 21:05:06 +0100 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cpack/dml/scripts/compression/bufs Tue Feb 09 21:05:06 2016 +0100 @@ -0,0 +1,35 @@ +#!/bin/sh +if [ $# -lt 3 ]; then + echo 'bufs <n:int> <command> <arg1> <arg2> ...' + echo + echo 'Apply command to arguments but buffering the nth argument' + echo 'of command (ie (n+1)th argument of strm) into a temporary file.' + echo 'This means that the nth argument can safely be replaced with' + echo 'a bash process redirection.' + exit 1 +fi +set -o nounset +set -e + +function str1 { + cmd="$1" + arg1="$2" + tmp=`mktemp -t strXXX` + # echo created $tmp 1>&2 + trap "rm -f $tmp; exit" INT KILL EXIT + shift 2 + (cat "$arg1" > $tmp) && $cmd $tmp "$@" +} + +function str { + pos=$1 + shift 1 + if [ $pos -eq 1 ]; then + str1 "$@" + else + cmd="$1 $2" + shift 2 + str $(($pos-1)) "$cmd" "$@" + fi +} +str "$@"