1

when I run the code below I get the error message "line 19: checkUser: command not found".

I have tried using shellcheck but I still couldn't fix the issue with the code.

#!/usr/bin/env bash

checkUser() {
    while true; do
       read -p "Enter username you would like to generate: " userName
       if id "$userName" >/dev/null 2&>1; then
          echo "Sorry user exists"
    else
          read -s -p "Enter password : " userPass
          echo adduser "$userName"
          printf "User %s has been added\n" "$userName"
          read -p "Enter group you want to assign user to: " userGroups
          useradd -G "userGroups" "$userName" &&
          printf "User has been added to group %s\n"  "$userGroups"
    fi
    read -p "Do you want to add another user? [y/n] " yn
    if [[ $yn = *[nN]* ]]; then
       break
   fi
done
}
checkUser
3
  • your script, although it has some logic errors, runs on my machine with no such error. Are you sure you don't have some weird control character inserted here or there in the script file ?
    – MelBurslan
    Commented Mar 31, 2016 at 0:23
  • What's missing after the &&
    – Jeff Schaller
    Commented Mar 31, 2016 at 0:28
  • is this a homework question? I've lost count of the number of times i've seen different people ask really basic and obvious questions about some variant of @val0x00ff 's script at unix.stackexchange.com/a/271569/7696 (each of the perpetrating the same mistaken use of #!/usr/bin/env)
    – cas
    Commented Mar 31, 2016 at 2:02

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.