I am trying to write a shell script to list all the users who have id 101
#!/bin/bash
who="$(who | cut -d ' ' -f 1 | sort -u )";
#Save the output of who
for user in ${who}; do # Iterate over $@
if [ $(echo id -g $user) == "101" ] ; then
echo "Got it";
fi
done;
when i execute my script I get this error "line 4: [: too many arguments". I am not sure where I made mistake.
$(id -g $user)
? Not sure why you need theecho
there. The result of the command should be sufficient, I think.who=...
;
to close thefor
loop after thefi