2018-06-26 Shell if/else

linux shell 之if-------用if做判断

  • if
str1 = str2    当两个串有相同内容、长度时为真 
int1 -eq int2   两数相等为真
  • If/else
if [[ $Order -gt 0 ]];then
    Process=`ps aux | grep $which | grep -vE 'grep' | awk '{print $2}'`
    echo $Process
else
    Process=`ps aux | grep $which | grep -vE 'grep' | awk '{print $2}' | sort -nr`
    echo $Process
fi
  • if/elif/else
if [ $1x == "ab"x ]; then
    echo "you had enter ab"
elif [ $1x == "cd"x ]; then
    echo "you had enter cd"
else
    echo "you had enter unexpected word"
fi

你可能感兴趣的:(2018-06-26 Shell if/else)