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