【发布时间】:2016-12-28 21:39:16
【问题描述】:
基本上,我正在尝试退出包含循环的子shell。这是代码: `
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
这不起作用。它从不说完成。当我按下停止时,它只会关闭对话框,但会继续写入文件。
编辑:我需要能够将变量从子 shell 传递到父 shell。但是,我需要继续写入文件并保持 Zenity 对话框出现。我该怎么做?
【问题讨论】:
-
我想我不明白。有没有特殊的方法可以退出子shell?