当我运行代码时,我的 shell 脚本中出现命令未找到错误

当我运行代码时,我的 shell 脚本中出现命令未找到错误

当我运行下面的代码时,我收到错误消息“第 19 行:checkUser:找不到命令”。

我尝试过使用外壳检查但我仍然无法用代码解决问题。

#!/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

相关内容