Bash has multiple ways of doing integer math. Focus on the recommended double parenthesis method and focus on conditionals. Using double parenthesis, you can check the return code of a mathematical operation and act on it.
- Bash has a ways of checking for numeric equivalence.…The POSIX compatible way is to use dash lt for less than,…dash gt for greater than, dash eq for equal,…dash le for less than or equal…and lastly, dash ge for greater than or equal.…These are pretty simple operators that…do exactly what you expect.…There are also greater than, less than…and equal symbols.…But, be careful, as they're string comparison operators,…not numeric comparison operators.…There are several older forms of doing integer math in Bash.…
These have all been replaced by two forms,…double parenthesis and dollar sign double parenthesis,…depending on if you want to output to standard out or not.…All of these methods do the same thing for the most part,…but because we're talking about conditionals,…we'll focus on the double parenthesis form.…To see how a numeric condition works…let's create a new file.…Make sure you're in your tilde slash bin directory…and type into a terminal.…Vi, space, numeric condition, dot sh…and hit enter.…Go into insert mode and add hash, bing, slash,…
Note: This course also helps you study to pass the Red Hat Certified Engineer (RHCE) exam—the benchmark certification for Red Hat Enterprise Linux.
- Basics of bash scripting
- Bash debugging
- Loading files in scripts
- Prompting for input
- Piping data into a script
- Outputting data from a script
- Controlling the flow of bash scripts with conditions
- Looping bash scripts
- Reviewing real-world examples