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

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)
主站蜘蛛池模板: 甘肃省| 乐都县| 巴林左旗| 东阳市| 郸城县| 荆门市| 夹江县| 哈尔滨市| 保康县| 扶沟县| 元谋县| 溧阳市| 三穗县| 樟树市| 甘谷县| 临沂市| 保山市| 泾川县| 三台县| 奎屯市| 盈江县| 安岳县| 石城县| 利辛县| 凤山市| 天柱县| 卢龙县| 姜堰市| 集贤县| 当涂县| 桂阳县| 同江市| 阳山县| 新巴尔虎左旗| 平南县| 阿拉尔市| 嘉祥县| 屏边| 徐州市| 扎鲁特旗| 江永县|