I am writing a script to read the output of a command to variable a and b. This is the script
#!/bin/bash
read a b < <(awk '/Application Server/ && !seen[$7]++{printf "%s ", $7}' /tmp/ServerState)
echo "The value of a is $a"
echo "The value of b is $b"
and getting the syntax error as :
line 3: syntax error near unexpected token `<'
line 3: `read a b < <(awk /Application Server/ && !seen[$7]++{echo "%s ", $7} /tmp/ServerState)'
But when I am typing the same command in the console it is working for me without any issue.
app@user:/tmp> read a b < <(awk '/Application Server/ && !seen[$7]++{printf "%s ", $7}' /tmp/ServerState)
app@user:/tmp> echo $a
FAILED
app@user:/tmp> echo $b
STARTED
Any help on this is really appreciated.
sh
(which in most (Debian-derived) systems is linked to dash
) doesn't allow process substitution. Try invoke by bash script.sh
. Same calling by ./script.sh executes with sha-bang
which is /bin/bash
in your script.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments