[英]cannot 'sudo' inside of bash if statement
我有双linux启动我是bash的新手
当运行以下脚本时我得到了奇怪的错误:
if [[ 'grep -i fedora /etc/issue' ]]; then
echo "the OS is Fedora"
$(sudo yum update -y && sudo yum upgrade -y)
else
echo "the OS is Ubuntu"
$(sudo apt-get update && sudo apt-get upgrade -y && sudo apt-get dist-upgrade -y)
fi
错误:./ server_update.sh:第9行:已加载:未找到命令
它试图执行apt-get / yum命令的输出,丢失$(..)
您在开始时也遇到问题:
if [[ -n "$(grep -i fedora /etc/issue)" ]]; then
是检查字符串是否存在的正确方法。
您的代码应如下所示:
if [[ -n "$(grep -i fedora /etc/issue)" ]]; then
echo "the OS is Fedora"
sudo yum update -y && sudo yum upgrade -y
else
echo "the OS is Ubuntu"
sudo apt-get update && sudo apt-get upgrade -y && sudo apt-get dist-upgrade -y
fi
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.