- Jun 6, 2005
- 194
- 0
- 0
hi guys
so im trying to compare two strings in terms of lexical order
for example
if i set VAR1="hi"
and then i set VAR2="bye"
and compare them, so for instance if the snippet of code looks like this:
######################################
set VAR1="hi"
set VAR2="bye"
if [ $VAR1 \< $VAR2 ] ; then
echo "$VAR1 is lexically less than $VAR2"
else
echo "$VAR1 is lexically greater than $VAR2"
fi
exit 0
######################################
when i run the program, the shell interpreter cannot identify the "<" operator
in general the "<" operator is a redirect operator, but i found a site that says if you
use the forward slash it'll interpret it as a string comparison operator.
while running that code i'm not running it on a c shell or bourne shell, but on a tcshell
because that's the only shell i have access to, but can somebody confirm that using \< should allow somebody to compare two strings lexically.
thanks in advance
so im trying to compare two strings in terms of lexical order
for example
if i set VAR1="hi"
and then i set VAR2="bye"
and compare them, so for instance if the snippet of code looks like this:
######################################
set VAR1="hi"
set VAR2="bye"
if [ $VAR1 \< $VAR2 ] ; then
echo "$VAR1 is lexically less than $VAR2"
else
echo "$VAR1 is lexically greater than $VAR2"
fi
exit 0
######################################
when i run the program, the shell interpreter cannot identify the "<" operator
in general the "<" operator is a redirect operator, but i found a site that says if you
use the forward slash it'll interpret it as a string comparison operator.
while running that code i'm not running it on a c shell or bourne shell, but on a tcshell
because that's the only shell i have access to, but can somebody confirm that using \< should allow somebody to compare two strings lexically.
thanks in advance
