pee is a C code from moreutils. You can do something with it like:
% pee bc bc 1+2 1+2 [Press Ctrl+D] 3 3 $ echo '1+2' | pee bc bc 3 3
pee accepts arguments as commands. It will feed those commands with the standard input it gets.
As usual for moreutils post, I wrote a Bash script, pees:
#!/bin/bash if (($# == 0)); then echo "Please specify command(s) as argument(s) of $(basename "$0")." exit 1 fi TMPFILE="$(mktemp)" while read line; do echo "$line" >> "$TMPFILE"; done for cmdargs in "$@"; do bash -c "$cmdargs" < "$TMPFILE"; done rm "$TMPFILE"
Needless to say, pees can do the examples above. But it can also do these as pee can:
% echo 1289371054 | awk '{print strftime("%c", $0, 1)}' > /tmp/tmpdate ; ./pees 'date -f /tmp/tmp date' 'date -f /tmp/tmpdate -u' <<< "" Wed Nov 10 14:37:34 CST 2010 Wed Nov 10 06:37:34 UTC 2010 $ date -u > /tmp/tmpdate ; ./pees 'date -f /tmp/tmpdate' 'date -f /tmp/tmpdate -u' <<< "" Wed Nov 10 14:49:46 CST 2010 Wed Nov 10 06:49:46 UTC 2010
First one is using a specific timestamp, then second is current timestamp. Since date doesn’t accept standard input, we have feed it with timestamp in file. pees receives empty standard input via Here Strings. As you can see, two date have different arugments, one with -u, the other without.
There are slightly differences between pee and pees, though both feed commands with data at once, but pee invokes commands before getting data. Therefore, if a command output something before it starts to receive from standard input, you will see the output first if you type in. For example:
% ./pee 'echo Hello ; while read line; do echo "$line"; done' Hello abc [Press Ctrl+D] abc $ ./pees 'echo Hello ; while read line; do echo "$line"; done' abc [Press Ctrl+D] Hello abc
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.