我在
中有这一行的脚本read -t 1800 -n1 -p ""$bldgrn" Do you want to update the mpd feed? [y/n/q/r] $(tput sgr0)" ynqr
在30分钟不活动后退出脚本。我怎样才能转向一个名为“endex”的函数?
“endex”是
function endex {
echo;
sleep 0;
clear;
exit
}
答案 0 :(得分:3)
如果read
超时,则其返回代码大于128
。所以
read -t 1800 -n 1 -p "${bldgrn}Do you want to update the mpd feed? [y/n/q/r]$(tput sgr0) " ynqr
if (($?>128)); then
endex
else
# no timeout here
fi
会做的。
help read
在-t
选项的说明中包含该信息。
确保{/ 1}}在读取语句之后。如果您需要一些中间命令,请保存if (($?>128))
的返回码:
read