bash : "set -e" and check if a user exists make script exit

Posted by Dahmad Boutfounast on Server Fault See other posts from Server Fault or by Dahmad Boutfounast
Published on 2012-04-05T16:34:12Z Indexed on 2012/04/05 17:33 UTC
Read the original article Hit count: 396

Filed under:
|
|
|
|

i am writing a script to install a program with bash, i want to exit on error so i added "set -e" in the beginning of my script. the problem is that i have to check if a user exists inside of my script, to do this i am using "grep "^${USER}:" /etc/passwd", if the user exists, the script runs normally, but if the user doesn't exist, this command exists, and i don't want to exit on this case (i have to create the user and continue my installation).

so what's the solution to make my script continue running ?? i tried to redirect the output of "grep" to a variable, but i still have the same problem :(

thanks.

© Server Fault or respective owner

Related posts about linux

Related posts about bash