-
Notifications
You must be signed in to change notification settings - Fork 1.9k
SC2073
Vidar Holen edited this page Jul 20, 2019
·
1 revision
if [ "aardvark" < "zebra" ]
then
echo "Alphabetical!"
fiif [ "aardvark" \< "zebra" ]
then
echo "Alphabetical!"
fior optionally in Bash/Ksh:
if [[ "aardvark" < "zebra" ]]
then
echo "Alphabetical!"
fiYou are using the operator < or > in a [ test expression.
In this context, it will be considered a file redirection operator instead, so [ "aardvark" < "zebra" ] is equivalent to [ "aardvark" ] < ./zebra, which is true if there exists a readable file zebra in the current directory.
If you wanted to compare two strings lexicographically (alphabetically), escape the < or > with a backslash as in the correct example.
If you want to compare two numbers numerically, use -lt or -ge instead.
None.
- Help by adding links to BashFAQ, StackOverflow, man pages, POSIX, etc!