Michael C. Toren on Sun, 16 Jan 2000 15:57:45 -0500 (EST)


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: [PLUG] check for existing user


> if ("grep /etc/passwd -e $USERNAME")
>     $USER_EXISTS=1;
>     do this;
> fi
> 
> (I'm not sure if the quotes should be double-quotes, single-quotes, or
> back-ticks.)  The syntax above is probably horribly broken (resembling C
> more than shell scripting), but it gives the basic idea of what I'm
> thinking.  If this won't work, I'd love to know how to do it.

You don't need any type of quotes after the if statement.  Just type the
command whose return value is to be tested exactly as you would on the
command line.  However, you *do* need to include the word "then" following
the if statement, prior to any commands within the if block.

Also, if testing to see if a username exists in the password file, I would
recommend using a regex that looks more like ^${USERNAME}:

-mct