Bash脚本的语法是否适用于if elif语句

时间:2017-06-27 16:24:44

标签: bash shell

我在我的bash shell脚本的if,elseif条件中添加了另一个条件。我是shell脚本的新手,如果条件的语法正确,特别是“fi”实现,你们可以查看我的代码。非常感激。

    if [ -f /etc/system-release ] && grep Amazon /etc/system-release > /dev/null; then


cd /tmp
sudo yum install -y https://s3.amazonaws.com/ec2-downloads-windows/SSMAgent/latest/linux_amd64/amazon-ssm-agent.rpm

else
  # we're either RedHat or Ubuntu
  DISTRIBUTOR=`lsb_release -is`
  DISTRIBUTOR2=`lsb_release -cs`

  if [ "trusty" == $DISTRIBUTOR2 ]; then

    cd /tmp         
    wget https://s3.amazonaws.com/ec2-downloads-windows/SSMAgent/latest/debian_amd64/amazon-ssm-agent.deb
    sudo dpkg -i amazon-ssm-agent.deb
    sudo start amazon-ssm-agent

   elif [ "RedHatEnterpriseServer" == $DISTRIBUTOR ]; then

    cd /tmp
    sudo yum install -y https://s3.amazonaws.com/ec2-downloads-windows/SSMAgent/latest/linux_amd64/amazon-ssm-agent.rpm

   elif [ "xenial" == $DISTRIBUTOR2 ]; then

    cd /tmp         
    wget https://s3.amazonaws.com/ec2-downloads-windows/SSMAgent/latest/debian_amd64/amazon-ssm-agent.deb
    sudo dpkg -i amazon-ssm-agent.deb
    sudo systemctl enable amazon-ssm-agent
  fi


fi

sleep 10

1 个答案:

答案 0 :(得分:0)

看起来基本没问题,但是https://www.shellcheck.net/有一些你应该解决的评论。

相关问题