2013-11-26 88 views
0

我试图退出我的脚本,当用户按提示输入部门号码时输入。然而,由于某种原因,它不是退出,我不知道为什么?我一直在试图弄清楚这个问题。谢谢您的帮助。下面是代码:&&返回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 
+0

第二(主)'while'循环中没有'break'? – PeterMmm

+0

当你用'set -x'运行脚本时,你会看到什么? –

回答

2

你可以尝试使用exit 1,而不是return 1exit 0代替return 0

你的回报是写在一个函数,所以它不能完成比你的功能的任何其他。

+2

downvote是很好的,但它会更好地证明你的意见。 –

+1

我不知道为什么会得到downvoted :(但改变它退出1固定我的问题,所以给予好评和认可!谢谢! – Whoppa

+0

不客气:) –