make getpeername() return the original socket address which before it was intercepted
[hband-tools.git] / user-tools / ffilt
blob4b752b05fa2c2a053f5cdc2ddce4451265e2549e
1 #!/bin/bash
3 true <<'EOF'
4 =pod
6 =head1 NAME
8 ffilt - Filter a file via a command's STDIO and write back to it
10 =head1 SYNOPSIS
12 ffilt I<FILE> I<COMMAND> [I<ARGS>]
14 =head1 DESCRIPTION
16 Feed I<FILE> into I<COMMAND>'s stdin, then save its stdout back to I<FILE>
17 if I<COMMAND> ran successfully.
19 Similar to this shell script:
21 output=`cat I<FILE> | I<COMMAND>`
22 [ $? = 0 ] && echo "$output" > I<FILE>
24 =head1 LIMITATIONS
26 =head1 SEE ALSO
28 sponge(1), insitu(1) L<https://github.com/athas/insitu>
30 =cut
32 EOF
35 set -e
36 set -o pipefail
37 set -u
39 . /usr/lib/tool/bash-utils
42 opt_verbose=no
45 while [ $# != 0 ]
47 case "$1" in
48 --help)
49 pod2text "$0"
50 exit 0;;
51 -v|--verbose)
52 opt_verbose=yes
54 --)
55 shift
56 break;;
57 -*)
58 errx -1 "unknown option: $1";;
60 break;;
61 esac
62 shift
63 done
65 set -e
66 set -o pipefail
67 set -u
69 file=$1
70 shift
72 stdout=`cat "$file" | command "$@"`
73 # pipefail make us die here if either cat or command failed
74 cat > "$file" <<< "$stdout"