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
Liam
  • 23
  • 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 Mar 31 '16 at 00:23
  • What's missing after the && – Jeff Schaller Mar 31 '16 at 00: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 http://unix.stackexchange.com/a/271569/7696 (each of the perpetrating the same mistaken use of #!/usr/bin/env) – cas Mar 31 '16 at 02:02

0 Answers0