Reputation: 745
I've been trying to write a script that adds a non-root user. Is it possible to use variables and adduser to do it? I've tried just adduser bob
and it works perfectly fine, so why does adduser $user return adduser: Only one or two names allowed.
?
#!/bin/bash
read -p 'Do you want to add a non-root user? [y/N]' answer
case "${answer}" in
[yY]|[yY][eE][sS])
echo -e "What will the username be?"
read $user
adduser $user;;
[nN]|[nN][oO])
echo "Skipping";;
esac
Upvotes: 3
Views: 932
Reputation: 84579
Your problem is you are not adding anyone. In your script you have:
read $user
it should be
read user
Also note the correct command is useradd
. adduser
, if it exists, is generally just a link to useradd
.
Upvotes: 7