基本上,我试图退出包含循环的子壳。这里是代码: `如何退出子壳
stop=0
( # subshell start
while true # Loop start
do
sleep 1 # Wait a second
echo 1 >> /tmp/output # Add a line to a test file
if [ $stop = 1 ]; then exit; fi # This should exit the subshell if $stop is 1
done # Loop done
) | # Do I need this pipe?
while true
do
zenity --title="Test" --ok-label="Stop" --cancel-label="Refresh" --text-info --filename=/tmp/output --font=couriernew # This opens Zenity and shows the file. It returns 0 when I click stop.
if [ "$?" = 0 ] # If Zenity returns 0, then
then
let stop=1 # This should close the subshell, and
break # This should close this loop
fi
done # This loop end
echo Done
这是行不通的。它从不说完成。当我按下Stop时,它只是关闭对话框,但一直写入文件。
编辑:我需要能够将一个变量从subshell传递到父shell。但是,我需要继续写入文件并保持Zenity对话框出现。我将如何做到这一点?
我不认为我理解。有退出子壳体的特殊方法吗? – Feldspar15523