I'm a newbie in bash scripting and I have a problem with the aggrupation of the commands. Precisely in this line of code:
timeout -s 9 1 echo $var | nc localhost port
I'm trying to send data of a variable var via netcat to localhost in a specific port, and I want to timeout that command for 1 second. Reading the man pages of timeout I understand that it should be used as:
timeout -s SIGNAL TIME COMMAND
My question is how to replace COMMAND with the piped command echo $var | nc localhost port and for further knowledge how to write correctly the next situations:
COMMAND1 | (COMMAND2 | COMMAND3)
and
(COMMAND1 | COMMAND2) | COMMAND3
If I'm correct, the second example is equivalent to
COMMAND1 | COMMAND2 | COMMAND3
but I don't know how to write the first one.
echo "$var" | timeout -s 9 1 nc localhost port
That wouldn't solve the overall issue of timing out an entire pipeline though.timeout -s9 1 nc localhost port <<<$var
(unless it contains globs you want expanded, or whitespace to be normalized)