我试图退出我的脚本,当用户按提示输入部门号码时输入。然而,由于某种原因,它不是退出,我不知道为什么?我一直在试图弄清楚这个问题。谢谢您的帮助。下面是代码:&&返回1不终止脚本?
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
第二(主)'while'循环中没有'break'? – PeterMmm
当你用'set -x'运行脚本时,你会看到什么? –