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

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)
主站蜘蛛池模板: 泽库县| 紫云| 桐柏县| 于田县| 沐川县| 蕲春县| 乌审旗| 福鼎市| 岑巩县| 旬阳县| 广宁县| 阿勒泰市| 房产| 思南县| 曲水县| 夏河县| 德昌县| 鄂伦春自治旗| 金沙县| 宁明县| 金塔县| 上栗县| 彭泽县| 侯马市| 延吉市| 吴江市| 修武县| 文成县| 滁州市| 明水县| 延寿县| 游戏| 射洪县| 临颍县| 奉化市| 彩票| 九龙城区| 永宁县| 嘉兴市| 滨海县| 冷水江市|