&安培;&安培;返回1没有终止脚本?

时间:2013-11-26 08:42:00

标签: linux bash shell unix

当用户在提示输入部门编号时按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

1 个答案:

答案 0 :(得分:2)

您可以尝试使用exit 1代替return 1exit 0代替return 0

你的回报是用函数写的,所以它不能完成除你的函数以外的任何事情。