In Bash, you should do your check in an arithmetic context:
if (( a > b )); then
...
fi
For POSIX shells that don’t support (())
, you can use -lt
and -gt
.
if [ "$a" -gt "$b" ]; then
...
fi
You can get a full list of comparison operators with help test
or man test
.
More Related Contents:
- What does 2>&1 mean here?
- How to reload .bashrc settings without logging out and back in again?
- How do I iterate over a range of numbers defined by variables in Bash?
- Why would a correct shell script give a wrapped/truncated/corrupted error message? [duplicate]
- When do we need curly braces around shell variables?
- Quick-and-dirty way to ensure only one instance of a shell script is running at a time
- Multi-dimensional arrays in Bash
- How do I check if a directory exists in a Bash shell script?
- Capture stdout and stderr into different variables
- How to determine the current interactive shell that I’m in (command-line)
- Associative arrays in Shell scripts
- How to get the part of a file after the first line that matches a regular expression
- Open and write data to text file using Bash?
- bash set -e and i=0;let i++ do not agree
- How do I echo stars (*) when reading password with `read`?
- Why is this bash prompt acting strangely/disappearing, and how do I fix it (OS X)?
- Why is “[[ 10 < 2 ]]" true when comparing numbers in bash? [duplicate]
- Bash: Copy named files recursively, preserving folder structure
- How to go to each directory and execute a command?
- Read a variable in bash with a default value
- Relative paths based on file location instead of current working directory [duplicate]
- Counting lines or enumerating line numbers so I can loop over them – why is this an anti-pattern?
- Execute command containing quotes from shell variable [duplicate]
- What does “export” do in shell programming? [duplicate]
- What is the most elegant way to remove a path from the $PATH variable in Bash?
- pipe stdout and stderr to two different processes in shell script?
- How can I convert tabs to spaces in every file of a directory?
- How to match a single quote in sed
- How to update one file in a zip archive
- How to read variables from file, with multiple variables per line?