The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
[sh] String comparison operators userix Shell Programming and Scripting 1 05-16-2008 01:09 AM
string comparison Jatsui Shell Programming and Scripting 5 02-04-2008 01:28 PM
string comparison fedora Shell Programming and Scripting 2 01-03-2007 12:20 PM
Get Comparison operators from with RexExp umen Shell Programming and Scripting 3 07-19-2006 07:38 AM
String Comparison abey High Level Programming 1 10-19-2005 09:08 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #8  
Old 02-13-2006
vino's Avatar
Supporter (in vino veritas)
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,698
Quote:
Originally Posted by ballazrus
Code:
#! /bin/sh

read A B

if [ $A < $B ] ; then
        echo "$A is less than $B"
else
        echo "$A is greater than $B"
fi

exit 0

intranet (119) % sh strcmp.sh
hi bye
strcmp.sh: bye: cannot open <-- error message


so i'm using the < as a string operator but it detects it as a redirect.

and basically A and B are read in from the keyboard

thanks for your patience by the way, i know it's late, at least where i live hehe
Code:
#! /bin/sh

read A B

if [[ $A < $B ]] ; then
        echo "$A is less than $B"
else
        echo "$A is greater than $B"
fi

exit 0
Reply With Quote
Forum Sponsor
  #9  
Old 02-13-2006
Registered User
 

Join Date: Feb 2006
Posts: 10
i tried the other one too with the double brackets and it doesnt give me the right result. it does show an error but will go through the whole execution of the program, but as mentioned before, the result isn't correct

this is what happens

intranet (121) % sh strcmp.sh
hi bye
strcmp.sh: [[: not found
hi is greater than bye

intranet (122) % sh strcmp.sh
bye hi
strcmp.sh: [[: not found
bye is greater than hi

so in the first run, i type in hi and bye, it says the [[ part of the code not found...i take it that it cant interpret double brackets.

and it goes to the else statement.

in the second run i type in bye before hi, and it goes to the else statement again, while it should've been the first if statement.

i'm going to have to try it out on a real c shell to see what the result turns out to be.
Reply With Quote
  #10  
Old 02-13-2006
vino's Avatar
Supporter (in vino veritas)
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,698
I guess it must have something to do with the vmware machine.
Reply With Quote
  #11  
Old 02-13-2006
Registered User
 

Join Date: Feb 2006
Posts: 10
i'mnot using it with vmware at the moment, but i'm using SPARC, i think it's based on unix, hence why it keeps interpreting the > and < as redirect. however the double brackets arent working either. i found another forum where a user had posted his code which looks just like the one with the double brackets and he's having the same problem.

i will have to test both codes tomorrow on my school's vmware.
Reply With Quote
  #12  
Old 02-13-2006
Registered User
 

Join Date: Feb 2006
Posts: 10
hi, vino, i just wanted to say thanks for your help. i d/led cygwin and ran the code for the double brackets and it works like a charm. i think cygwin is a c shell emulator? or perhaps bourne shell. either way it's working great.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 10:09 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0