From the course: Linux System Engineer: Bash Shell Scripting for Automation

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Numeric conditions

Numeric conditions

From the course: Linux System Engineer: Bash Shell Scripting for Automation

Start my 1-month free trial

Numeric conditions

- 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…

Contents