我对 bash 脚本末尾的退出代码的含义感到困惑:我知道退出代码 0 表示它成功完成,并且还有更多的退出代码编号(如果我没记错的话,是 127?)
我的问题是当在脚本末尾看到退出代码 0 时,它是否会强制退出代码为 0,即使脚本失败还是有其他含义?
我试图在使用read命令时仅启用某些选项,并在输入错误的可能性时退出脚本。
尝试了很多可能性(数组、变量、语法更改),但我仍然坚持我最初的问题。
如何测试用户的输入并允许 \disallow 运行脚本的其余部分?
#!/bin/bash
red=$(tput setaf 1)
textreset=$(tput sgr0)
echo -n 'Please enter requested region > '
echo 'us-east-1, us-west-2, us-west-1, eu-central-1, ap-southeast-1, ap-northeast-1, ap-southeast-2, ap-northeast-2, ap-south-1, sa-east-1'
read text
if [ -n $text ] && [ "$text" != 'us-east-1' -o us-west-2 -o us-west-1 -o eu-central-1 -o ap-southeast-1 -o ap-northeast-1 -o ap-southeast-2 -o ap-northeast-2 -o ap-south-1 -o sa-east-1 ] ; then
echo 'Please enter the region name in its correct form, as describe above'
else
echo …Run Code Online (Sandbox Code Playgroud) 我正在尝试运行一个脚本,该脚本将检查带有 gui 的 linux 机器上的互联网速度,关闭终端窗口,当查询完成时,窗口将给出答案。至于暂时——我可以把窗户放下,但不能打开。
#!/bin/bash
xdotool getactivewindow windowminimize
#xdotool set_window --name speedy
#xdotool set_window --icon-name speedy
speedtest-cli --simple
if [ $? -eq 0 ]
then
#xdotool windowactivate speedy
xdotool windowfocus #speedy
xdotool key "F11"
fi
exec $SHELL
Run Code Online (Sandbox Code Playgroud) bash ×2
shell-script ×2
exit ×1
exit-status ×1
scripting ×1
shell ×1
window ×1
x11 ×1
xdotool ×1