Can one use multiple here-docs to provide input to a command in bash?
$ cat <<<foo <<<bar
bar
$ cat <<EOF1 <<EOF2
> foo
> EOF1
> bar
> EOF2
bar
Obviously, in both cases, the second here-doc is used as stdin, and replaces the first reference. Is the solution to use echo
s instead?
$ cat <(echo -n foo) <(echo bar)
foobar
Also, for some reason, using a combination didn't work for me. Why would that be?
$ cat <<<foo <(echo bar)
bar
$ cat <(echo -n foo) <<<bar
foo
Best Answer
You can do:
There can be only one stdin, as there's only one file descriptor 0.
is short for:
And:
is:
You have to make up your mind what to open on file descriptor 0.
Is:
Where
123
is a file descriptor to a pipe, and in parallel, bash runsecho foo
in another process with the stdout redirected to the other end of the pipe.Once you pass a filename to
cat
,cat
no longer read from stdin. You'd need:Or:
(
-
is to tellcat
to read from stdin).