- 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)
推薦閱讀
- PowerCLI Cookbook
- Animate CC二維動畫設計與制作(微課版)
- Highcharts Cookbook
- Haskell Data Analysis Cookbook
- Getting Started with Eclipse Juno
- C語言程序設計
- C++反匯編與逆向分析技術揭秘(第2版)
- PHP編程基礎與實踐教程
- Illustrator CC平面設計實戰從入門到精通(視頻自學全彩版)
- 動手打造深度學習框架
- 自學Python:編程基礎、科學計算及數據分析(第2版)
- 實戰Java高并發程序設計(第2版)
- ASP.NET 4.0 Web程序設計
- Continuous Delivery and DevOps:A Quickstart Guide Second Edition
- Mastering Machine Learning with R