From: PRC on
Hi All,
Is there a easy way in bash to pass the output of running CMD1 to
2 or more commands CMD2, CMD3, ... etc, without saving the output of
CMD1 to a temporary file?
It is no good saving the output in a varible since bash converts the
tailing '\r's to spaces.
The tranditional way looks like:
CMD1>tmpfile
CMD2<tmpfile
CMD3<tmpfile
....
CMDn<tmpfile
rm -f tmpfile


Best Regards,
PRC
Apr 18, 2008
From: Florian Kaufmann on
In bash yes. It's a non POSIX solution.

cmd1 | tee >(cmd2) >(cmd2) >(cmd...) | cmdN

Flo
From: Florian Kaufmann on
In bash yes. It's a non POSIX solution.

cmd1 | tee >(cmd1) >(cmd2) >(cmd...) | cmdN

Man tee says:
tee [OPTION]... [FILE]...
Copy standard input to each FILE, and also to standard output.

>(...) is the syntax for process substitution. Simplified, it can stay where ever a command expects a file name as argument to which it will write. <(...) likewise for files the process will read from.

http://tldp.org/LDP/abs/html/process-sub.html

Flo
From: Dave B on
On Friday 18 April 2008 05:45, PRC wrote:

> It is no good saving the output in a varible since bash converts the
> tailing '\r's to spaces.

No it doesn't, unless you let it do that.

$ ls
file1 file2 file3 file4
$ myvar=`find -type f`
$ echo $myvar # lose format
../file1 ./file2 ./file3 ./file4
$ echo "$myvar" # keep format
../file1
../file2
../file3
../file4

--
D.