Can I pass the output of some command to two or more commands without

Can I pass the output of some command to two or more commands without

am 18.04.2008 05:45:30 von PRC

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 CMD3 ....
CMDn rm -f tmpfile


Best Regards,
PRC
Apr 18, 2008

Re: Can I pass the output of some command to two or more commandswithout

am 18.04.2008 06:56:51 von Dan Stromberg

On Thu, 17 Apr 2008 20:45:30 -0700, PRC wrote:

> 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 > CMD3 > ...
> CMDn > rm -f tmpfile
>
>
> Best Regards,
> PRC
> Apr 18, 2008

This came up on the group recently - you might check the archives.

Anywaye, here's the option I like to use in my shell scripts:

http://stromberg.dnsalias.org/~strombrg/mtee.html

Re: Can I pass the output of some command to two or more commands

am 18.04.2008 07:58:37 von Florian Kaufmann

In bash yes. It's a non POSIX solution.

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

Flo

Re: Can I pass the output of some command to two or more commands

am 18.04.2008 08:04:36 von Florian Kaufmann

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

Re: Can I pass the output of some command to two or more commands without using a temporay file?

am 18.04.2008 10:20:48 von Dave B

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.