Awk: syntax error near unexpected token `('

I tried to assign the output of the command to a awkvariable:

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?

+4
source share
1 answer

I assume that you are using #!/bin/shand not #!/bin/bashthat process substitution is not available (or you have a bash version that does not support the subsicyution procedure, pre 4.XX). Go to bashor simply type win the command awk:

USERS=$(w | awk '/\/X/ {print $1}')
+6
source

All Articles