你有什麼對我的作品:
$ cat test-shell-exit
#!/bin/sh
check()
{
printf "Would you like to try again?\n"
read S
if [ "$S" = "y" ]
then
echo Try again
else
echo Done
exit 0
fi
}
echo Before
check
echo After
$ ./test-shell-exit
Before
Would you like to try again?
y
Try again
After
$ ./test-shell-exit
Before
Would you like to try again?
n
Done
難道你試試這個測試案例,並與來自任何差異更新你的答案?看來你遇到的問題是由你沒有提到的東西造成的。
更新:再次使用一個循環而不是調用程序的例子:
$ cat test-shell-exit
#!/bin/sh
check()
{
printf "Would you like to try again?\n"
read S
if [ "$S" = "y" ]
then
echo Try again
else
echo Done
exit 0
fi
}
while true; do
echo Before
check
echo After
done
$ ./test-shell-exit
Before
Would you like to try again?
y
Try again
After
Before
Would you like to try again?
y
Try again
After
Before
Would you like to try again?
n
Done
它幫助,如果您發佈包含退出腳本的一部分。 – rsp 2009-11-29 21:26:15
我發佈我的代碼 – goe 2009-11-29 21:28:19
測試代碼是否與check shell過程在同一實際shell源文件中調用'check'? – DigitalRoss 2009-11-29 21:42:00