How to test strings for lexicographic less than or equal in Bash?
You can flip the comparison and sign around and test negatively:
$ a="abc"
$ b="abc"
$ if ! [[ "$b" > "$a" ]] ; then echo "a <= b" ; fi
a <= b
If you want collating sequence of "A" then "a" then "B"... use:
shopt -s nocaseglob
You need to use ||
with an additional condition instead of <=
:
[[ "$a" < "$b" || "$a" == "$b" ]]
Just negate the greater than test:
if [[ ! "a" > "b" ]]