Aug 10, 2006 #1 signalsys Technical User Joined Sep 5, 2005 Messages 44 Location CN two string variables: var1="0123' var2='01BD' What syntax should i use to compare the two variables and output the bigger one? Thanks in advance.
two string variables: var1="0123' var2='01BD' What syntax should i use to compare the two variables and output the bigger one? Thanks in advance.
Aug 10, 2006 #2 columb IS-IT--Management Joined Feb 5, 2004 Messages 1,231 Location EU You say you want to output the bigger one. This implies that the strings are, in fact, hex digits. I'm not sure you can compare hex digits in ksh. In general terms the symbols > < = <= >= refer to string comparison and -lt -le -eq -gt -ge refer to numeric comparison so Code: # print numeric biggest var [[ $var1 -gt $var2 ]] && echo $var1 || echo $var2 # print dictionary bigest var [[ $var1 > $var2 ]] && echo $var1 || echo $var2 but neither work for hex. Ceci n'est pas une signature Columb Healy Upvote 0 Downvote
You say you want to output the bigger one. This implies that the strings are, in fact, hex digits. I'm not sure you can compare hex digits in ksh. In general terms the symbols > < = <= >= refer to string comparison and -lt -le -eq -gt -ge refer to numeric comparison so Code: # print numeric biggest var [[ $var1 -gt $var2 ]] && echo $var1 || echo $var2 # print dictionary bigest var [[ $var1 > $var2 ]] && echo $var1 || echo $var2 but neither work for hex. Ceci n'est pas une signature Columb Healy
Aug 10, 2006 #3 cspilman MIS Joined Nov 17, 2000 Messages 307 Location US If you're comparing hex values, you can try this Code: var1=`echo "16i 0123 p" | dc` var2=`echo "16i 01BD p" | dc` [[ $var1 -gt $var2 ]] && echo $var1 || echo $var2 Regards, Chuck Upvote 0 Downvote
If you're comparing hex values, you can try this Code: var1=`echo "16i 0123 p" | dc` var2=`echo "16i 01BD p" | dc` [[ $var1 -gt $var2 ]] && echo $var1 || echo $var2 Regards, Chuck