Mercurial > hg > dml-open-cliopatria
annotate 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 |
rev | line source |
---|---|
Daniel@0 | 1 #!/bin/sh |
Daniel@0 | 2 if [ $# -lt 3 ]; then |
Daniel@0 | 3 echo 'bufs <n:int> <command> <arg1> <arg2> ...' |
Daniel@0 | 4 echo |
Daniel@0 | 5 echo 'Apply command to arguments but buffering the nth argument' |
Daniel@0 | 6 echo 'of command (ie (n+1)th argument of strm) into a temporary file.' |
Daniel@0 | 7 echo 'This means that the nth argument can safely be replaced with' |
Daniel@0 | 8 echo 'a bash process redirection.' |
Daniel@0 | 9 exit 1 |
Daniel@0 | 10 fi |
Daniel@0 | 11 set -o nounset |
Daniel@0 | 12 set -e |
Daniel@0 | 13 |
Daniel@0 | 14 function str1 { |
Daniel@0 | 15 cmd="$1" |
Daniel@0 | 16 arg1="$2" |
Daniel@0 | 17 tmp=`mktemp -t strXXX` |
Daniel@0 | 18 # echo created $tmp 1>&2 |
Daniel@0 | 19 trap "rm -f $tmp; exit" INT KILL EXIT |
Daniel@0 | 20 shift 2 |
Daniel@0 | 21 (cat "$arg1" > $tmp) && $cmd $tmp "$@" |
Daniel@0 | 22 } |
Daniel@0 | 23 |
Daniel@0 | 24 function str { |
Daniel@0 | 25 pos=$1 |
Daniel@0 | 26 shift 1 |
Daniel@0 | 27 if [ $pos -eq 1 ]; then |
Daniel@0 | 28 str1 "$@" |
Daniel@0 | 29 else |
Daniel@0 | 30 cmd="$1 $2" |
Daniel@0 | 31 shift 2 |
Daniel@0 | 32 str $(($pos-1)) "$cmd" "$@" |
Daniel@0 | 33 fi |
Daniel@0 | 34 } |
Daniel@0 | 35 str "$@" |