官术网_书友最值得收藏!

Evaluating binary numbers

Let's say we want to introduce another if condition and use elif (short for else if):

#!/bin/bash
AGE=21
if [ ${AGE} -lt 18 ]; then
echo "You must be 18 or older to see this movie"
elif [ ${AGE} -eq 21 ]; then
echo "You may see the movie and get popcorn"
else
echo "You may see the movie!"
exit 1
fi

echo "This line might not get executed"

If AGE is set and equals 21, then the snippet will echo:

You may see the movie and get popcorn
This line might not get executed

Using if, elif, and else, combined with other evaluations, we can execute specific branches of logic and functions or even exit our script. To evaluate raw binary variables, use the following operators:

  • -gt (greater than >)
  • -ge (greater or equal to >=)
  • -lt (less than <)
  • -le (less than or equal to <=)
  • -eq (equal to)
  • -nq (not equal to)
主站蜘蛛池模板: 海晏县| 宝鸡市| 普洱| 乌鲁木齐县| 天峨县| 金沙县| 达孜县| 奉新县| 重庆市| 廊坊市| 卢氏县| 永和县| 横山县| 克拉玛依市| 陆丰市| 赤峰市| 武宣县| 石林| 井研县| 平泉县| 彭州市| 朔州市| 龙山县| 博罗县| 定结县| 云梦县| 巴塘县| 大渡口区| 玉龙| 邢台县| 高台县| 武强县| 永靖县| 海原县| 仁布县| 保靖县| 宣汉县| 奈曼旗| 秦安县| 新郑市| 桐柏县|