more safety checks in noshellinject; bugfix (perl string-comparision) in notashell...
[hband-tools.git] / user-tools / pipeby
blob60733f9a11c7b964ac9a069b3a874858cc4befde
1 #!/bin/bash
3 true <<'EOF'
4 =pod
6 =head1 NAME
8 pipeby - Run a command and pipe its output to an other one
10 =head1 SYNOPSIS
12 pipeby I<CMD_2> [I<ARGS> --] I<CMD_1> [I<ARGS>]
14 =head1 DESCRIPTION
16 Equivalent to this shell command:
18 CMD_1 | CMD_2
20 =head1 RATIONALE
22 It is simetimes more convenient to skip shell involvement.
24 =head1 SEE ALSO
26 pipexec(1)
28 =cut
30 EOF
33 set -e
34 set -o pipefail
35 set -u
37 if [ $# = 0 ]
38 then
39 pod2text "$0" >&2
40 exit 1
42 if [ "$1" = --help ]
43 then
44 pod2text "$0"
45 exit 0
48 declare -a cmd_1=()
49 declare -a cmd_2=()
51 cmd_2+=("$1")
52 shift
54 while [ $# != 0 ]
56 case "$1" in
57 --)
58 shift
59 cmd_2+=("${cmd_1[@]}")
60 cmd_1=()
61 break
64 cmd_1+=("$1")
66 esac
67 shift
68 done
70 cmd_1+=("$@")
72 "${cmd_1[@]}" | "${cmd_2[@]}"