基本上,我試圖退出包含循環的子殼。這裏是代碼: `如何退出子殼
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