2018年2月1日 星期四

【shell script】shell script的 "字串比較","數字相加","數字判斷","數字累加","取字串長度",的用法

shell script 的字串比較:
                  yn="GG"
                  if [ "${yn}" == "GG" ]; then
                         echo "is the same !!"
                  fi

shell script 的字串比較方法2 (如果上面判斷行不通):
                  yn="GG"
                  um="GG"
                  if [ ${yn} == ${um} ]; then
                         echo "is the same !!"
                  fi


shell script 的數字相加:
                  a="10"
                  b="20"
                  c=`expr $a + $b`

shell script 的數字判斷:
                  declare -i num="60"
                  if [ $num -gt 50 ]; then
                          echo "correct !!!"
                  fi

shell script 的數字累加:
                  count="1"
                  count=$(($count+1))
                  echo "$count"

shell script 的取字串長度:
                 STR="12345678"
                 LEN=`echo ${#STR}`
                 echo "STR length is $LEN" => 印出 "STR length is 8"