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

  • Bash Cookbook
  • Ron Brash Ganesh Naik
  • 159字
  • 2021-07-23 19:17:29

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)
主站蜘蛛池模板: 临沂市| 香港| 改则县| 福贡县| 勐海县| 柳州市| 炉霍县| 正阳县| 平舆县| 呼图壁县| 玉树县| 长寿区| 孟津县| 公主岭市| 永清县| 石泉县| 珠海市| 阿拉善右旗| 黄大仙区| 习水县| 威海市| 凤山市| 深州市| 九江市| 镇远县| 军事| 大丰市| 萨迦县| 邢台县| 淮南市| 泉州市| 四川省| 比如县| 库车县| 石门县| 徐闻县| 桂平市| 奉节县| 临武县| 寿阳县| 临西县|