Example, check if user is in a group.
echo groups
Berty adm, dialout, cdrom, foo, foo
how to check that 'dialout' is in that output
I thought of awk '{print $x}' but x won't aways be the same.
Thanks.
Example, check if user is in a group.
echo groups
Berty adm, dialout, cdrom, foo, foo
how to check that 'dialout' is in that output
I thought of awk '{print $x}' but x won't aways be the same.
Thanks.
I am assuming
has values
Berty adm, dialout, cdrom, foo, foo
a simple grep should get you
echo $groups | grep dialout
with awk
echo $groups | awk '/dialout/{ print $0 }'
With shell builtins:
case $groups in (*dialout*) echo "true";; esac
This is not precise though. Like the "grep" in the previous post. (The latter can be improved with "grep -w".)
Using an interim variable:
ngroups=${groups#* } # remove the prefix
[[ ,${ngroups// /}, == *,dialout,* ]] && echo yes || echo no # remove all other spaces; add , to beginning & end
You can use if
instead of the && ... ||
construct I used above. Or you can put it in MadeInGermany's case statement:
case ,${ngroups// /}, in (*,dialout,*) echo "true";; esac
Andrew