Bash - Test for multiple users

Posted by Mike Purcell on Super User See other posts from Super User or by Mike Purcell
Published on 2012-06-08T22:00:28Z Indexed on 2012/06/08 22:42 UTC
Read the original article Hit count: 247

Filed under:

I am trying to test if current user one of two allowed users to start a process, but I can't seem to get the multi-condition to work correctly:

test ($(whoami) != 'mpurcell' || $(whoami) != 'root')) && (echo "Cannot start script as non-ccast user..."; exit 1)

Is there a way to test multiple users without have to enter two lines, like this:

test $(whoami) != 'mpurcell' && (echo "Cannot start script as non-ccast user..."; exit 1)
test $(whoami) != 'root' && (echo "Cannot start script as non-ccast user..."; exit 1)

© Super User or respective owner

Related posts about bash