I am trying to get bash to process data from stdin that gets piped into, but no luck. What I mean is none of the following work:
echo "hello world" | test=($(< /dev/stdin)); echo test=$test
test=
echo "hello world" | read test; echo test=$test
test=
echo "hello world" | test=`cat`; echo test=$test
test=
where I want the output to be test=hello world
. I've tried putting "" quotes around "$test"
that doesn't work either.
The syntax for an implicit pipe from a shell command into a bash variable is
or
In your examples, you are piping data to an assignment statement, which does not expect any input.
Piping something into an expression involving an assignment doesn't behave like that.
Instead, try: