I tried to assign the output of an awk
command to a variable:
USERS=$(awk '/\/X/ {print $1}' <(w))
This line is part of the following script:
#!/bin/sh
INTERFACE=$1 # The interface which is brought up or down
STATUS=$2 # The new state of the interface
case "$STATUS" in
up) # $INTERFACE is up
if pidof dropbox; then
killall dropbox
fi
USERS=$(awk '/\/X/ {print $1}' <(w))
for user in $USERS; do
su -c "DISPLAY=$(awk '/\/X/ {print $11}' <(w)) dropboxd &" $user
done
;;
down) # $INTERFACE is down
;;
esac
However, I get the following error:
script: command substitution: line 14: syntax error near unexpected token `('
script: command substitution: line 14: `awk '/\/X/ {print $1}' <(w))'
All brackets are closed. Where is the syntax error?
I'm assuming because you are using #!/bin/sh
and not #!/bin/bash
that process substitution is not available (or you have a version of bash that doesn't support process subsitiution, pre 4.X.X). Switch to bash
or just pipe w
to your awk
command:
USERS=$(w | awk '/\/X/ {print $1}')
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments