gpt4 book ai didi

linux - shell 脚本 : How to enforce display of previous query if a statement is true?

转载 作者:太空宇宙 更新时间:2023-11-04 11:02:24 24 4
gpt4 key购买 nike

我写了一个自动安装 NRPE 的脚本,该脚本执行的步骤之一是询问您要如何安装守护进程 (standalone/xinetd)。如果用户选择 xinetd,我将运行检查文件 /etc/init.d/xinetd 是否存在,如果不存在,脚本会打印“Xinetd is not installed !”紧接着是 break

这是脚本的相关部分:

echo "How would you like to configure the NRPE daemon?"
select DMN in 'Xinetd' 'Standalone Daemon'; do
if [ "$DMN" = "Xinetd" ];
then
DMNMODE="xinetd"
if [ -e $XINETDSVC ]; then
cat << EOF > $XINETDFILE
service nrpe
{
flags = REUSE
type = UNLISTED
port = $NRPEPORT
socket_type = stream
wait = no
user = $NGUSER
group = $NGGROUP
server = /usr/sbin/nrpe
server_args = -c $NRPECFG --inetd
log_on_failure += USERID
disable = no
only_from = 127.0.0.1 $NAGIOSSRV
}
EOF
$XINETDSVC restart
else
echo "Xinetd is not installed!"
break
fi
break
elif [ "$DMN" = "Standalone Daemon" ];
then
DMNMODE="daemon"
chkconfig nrpe on ; $NRPESVC start
break
fi
done

想法是,如果文件不存在,这意味着 xinetd 没有安装,我希望脚本再次询问用户他想如何安装该服务。但实际上,当我运行脚本时,如果我选择 xinetdxinetd 没有安装,那么脚本会打印“Xinetd is not installed”然后继续脚本中的下一步。

我认为在 if 语句 中放置一个 break 会中断并将用户带回上一个问题......但事实并非如此,我是什么做错了吗?提前致谢

最佳答案

您希望仅在提供的输入有效时中断

break 将跳出 select

不要breakselect会再次循环。

关于linux - shell 脚本 : How to enforce display of previous query if a statement is true?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26476130/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com