Zenity不会取消或显示消息,因为它看不到变量

时间:2012-04-30 05:10:08

标签: bash variables wget zenity

我写了一个简单的脚本来wget和zenity取消:

#!/bin/bash
((
   wget http://d3qnbzt7ix5jlv.cloudfront.net/ubuntu-12.04-desktop-i386.iso & export PID=$$
   wait $PID
   export YES=$?
)&) | zenity --progress --pulsate --auto-close
if [ $? -eq 1 ]; then
  kill $PID
fi
if [ "$YES" = "0" ]; then
   zenity --info
elif [ "$YES" = "1" ]; then
   zenity --error
fi

不要看过程$ PID。 Zenity不显示最终窗口($ YES)。为什么呢?

1 个答案:

答案 0 :(得分:0)

这不完全是一个答案,但评论会使代码片段变得混乱:

/usr/bin/userinstall-wget

#!/bin/sh
# a wget wrapper to get these under a separate shell *and* progname

[ -n "$1" -a -n "$2" ] || exit 1

LANG=C \
wget -O "$1" --content-disposition --progress=bar:force:noscroll "$2" 2>&1 \
| stdbuf -i0 -o0 -e0 tr '>' '\n' \
| stdbuf -i0 -o0 -e0 sed -rn 's/^.*\<([0-9]+)%\[.*$/\1/p'
# NB: those coughing at this particular killall are welcome with patches
download() {
        userinstall-wget "$outfile" "$url" | (
                trap 'killall userinstall-wget' HUP
                zenity --progress --time-remaining --auto-close --auto-kill \
                        --text="Wait please..." \
                        --title="Downloading file"
        )
}

这些已作为ALT Linux的用户安装包装脚本的一部分被抛在一起。

HTH

PS:使用较旧的wget删除--progress=bar:force:noscroll