当用户在提示输入部门编号时按Enter键时,我正在尝试退出脚本。但由于某种原因,它不会退出,我不知道为什么?我一直在试图解决这个问题!谢谢您的帮助。这是代码:
checkDeptNum()
{
local input
while : ; do
read -p "Enter department number (Press ENTER to quit):" input
[ -z "$input" ] && return 1 #This is the line thats not working
while read line; do
if cut -d: -f3 "$file" | grep -w "$input"; then
break
else
r=$input
return 0
fi
done < Managers
error "Department number '$input' already exists in the file"
done
}
while : ; do
checkDeptNum
if [ -n "$r" ]; then
read -p "Enter the department name:" deptName
read -p "Enter the manager's name:" manName
read -p "Enter the manager's ID#:" manID
echo "$manName:$manID:$r:$deptName" >> "$file"
fi
done
答案 0 :(得分:2)
您可以尝试使用exit 1
代替return 1
和exit 0
代替return 0
你的回报是用函数写的,所以它不能完成除你的函数以外的任何事情。