2020-12-31 Linux Shell脚本if else 与或的用法

                 Linux Shell脚本if else 与或的用法

 

一、关于判断,linux shell脚本中不是用else if而是用elif的写法

二、测试实例

#!/bin/bash

if [[ $1 = 'android' ]]; 
then
  echo "Input is android"
elif [[ $1 = 'twitter' ]] || [[ $1 = 'youtube' ]];
then
  echo "Input is $1"
elif [[ $1 = 'trump' ]] && [[ $2 = 'stone' ]];
then
  echo "Input is $1 and $2"  
else
  echo "on any argument!"
fi

三、运行测试结果。

xxx@ubuntu:/opt$ ./test.sh 
on any argument!
xxx@ubuntu:/opt$ ./test.sh android
Input is android
xxx@ubuntu:/opt$ ./test.sh youtube
Input is youtube
xxx@ubuntu:/opt$ ./test.sh twitter
Input is twitter
xxx@ubuntu:/opt$ ./test.sh stone
on any argument!
xxx@ubuntu:/opt$ ./test.sh trump stone
Input is trump and stone

 

你可能感兴趣的:(linux,shell脚本)