This reads from stdin:
echo foo | tee >(read line </dev/stdin; echo "internal $line")
You have to keep in mind that a process substitution acts "like" a file.
It could be used where a file is expected. The command tee expects to write to a file.
In that command we are being specific about the device to read from with: /dev/stdin. In that simple example, the /dev/stdin could be removed and that will work also:
echo foo | tee >(read line; echo "internal $line")
If I am understanding your need correctly, this will work:
$ echo foo | tee >(read a </dev/stdin; echo "a is $a") \
>(read b </dev/stdin; echo "b is $b") \
>(read c </dev/stdin; echo "c is $c")
foo
a is foo
c is foo
b is foo
I omitted the PS2 prompt to reduce confusion. Note that each Process Substitution replaces the use of a file (as: tee FILE FILE ....
).
The read does not have to be the first command.
$ echo foo > >(echo "hello" | read b; read a </dev/stdin; echo "a is $a")
a is foo
Note that here the "Process Substitution" needs a redirection,
that is the reason of the two > >(
idiom.
A simple echo, will only print the number of the fd used (the name of the file):
$ echo >(echo "hello")
/dev/fd/63
hello
It is similar to:
$ echo "$file"
filename
Whereas this is a very different idiom:
$ echo > "$file"
-
points to stdin. – kenorb Dec 06 '15 at 19:25<(cat)
, and I am looking for:>(cat -)
. – kenorb Dec 06 '15 at 19:37cat | { cat <(sed 's/^/from the terminal: /'); }
the single pipeline will get you a single process group. – mikeserv Dec 06 '15 at 19:41echo foo | tee >(cat) >(cat)
? – muru Dec 06 '15 at 19:46echo foo >(cat)
because it doesn't make a lot of sense. theecho
happens after thecat
. see ^ muru's comment. – mikeserv Dec 06 '15 at 19:46cat
. However I wanted to specify stdin for the script which accepts file as part of-i
, so normally I could use/dev/stdin
. Is there any equivalent descriptor which I can use? So I could use:>(unknown_cmd1 /dev/stdin)
. Howcat
does it know its stdin? – kenorb Dec 06 '15 at 19:49echo foo | tee >(foo -i <(cat)
)?foo
being this hypothetical command? (An example:echo foo | tee >(cat -n <(cat))
) – muru Dec 06 '15 at 19:50>(cmd1 -i <(cat))
assuming that<(cat)
would return the file descriptor. – kenorb Dec 06 '15 at 19:52echo stuff | cmd /dev/fd/0
. you wont have a lot of luck editing it in-place, though, if that's what-i
is for. and thats either way. or for multiple:echo stuff | { { tee /dev/fd/3 | cmd1 /dev/fd/0 >&4; } 3>&1 | cmd2 /dev/fd/0; } 4>&1
– mikeserv Dec 06 '15 at 19:53/dev/fd/X
instead of just printing content of it. But it's actually the output of the echo. But the content from pipe isn't actually shown (because of being in the background). So actually it works as expected. E.g.:cat /etc/hosts | tee &>/dev/null >(dd if=/dev/stdin of=/dev/stdout) >(dd if=/dev/stdin of=/dev/stdout)
I guess. So my example was wrong, it suppose to be:echo foo | tee >(cat /dev/stdin) >(cat /dev/stdin)
which then it works. – kenorb Dec 06 '15 at 20:01tee FILE FILE FILE
where each FILE is a Process substitution that reads (probably with read) from stdin (look at my answer). Therefore I believe that this is not the same question asProcess substitution and cat: can't read stdin
. I respectfully ask to reconsider the "mark as duplicate". Look especially after the> >(
idiom. – Dec 06 '15 at 23:57