Chirality
Chirality

Reputation: 745

Add-user script not working, running: read $user; useradd $user

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

Answers (1)

David C. Rankin
David C. Rankin

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

Related Questions