Unfortunately, if you have $USER defined to something, "$USERNAME" may be interpreted as "$USER"NAME (ie
the value of $USER, followed by "NAME".
To avoid this, use curly braces {} (see man bash):
ie ${USERNAME}
This makes it 100% clear to the shell that you want to use the value of the variable "USERNAME".
Centinul also has an interesting point. Variable names are indeed case sensitive.
Also, for clarity, include the ENTIRE string in "" when there's a variable that needs to be expanded inside it.
So use "/home/${USERNAME}" not /home/"$USERNAME" or something.
When you want to use the output string of a command like echo, you need to include it in backquotes: ``.
Double quotes won't do the trick.
"echo $myVar" is nothing more than a string "echo <value of myVar is put here>".
`echo $myVar` will echo the value of $myVar.
ie a=`echo $myVar|sed -e 's/foo/bar/'` echoes $myVar's value, replaces "foo" with "bar" and stores the result
in $a.
Finally, note that useradd takes care of the "chown" and "chgrp" for you. When you use "useradd" to add a user, it will automatically create the user's home dir, using appropriate owner/group.
The "-R" option of chmod is unnecessary. Blocking r/x permission on the home directory to everyone but the
owner will effectively prevent everyone (except the user in question) from accessing anything under that home directory.
But I'm wondering if useradd also doesn't do that for you (depends on config, probably).
Use useradd's -c option to specify the user's "full name" in the password file. chfn does something different.
|