02-13-2006
string comparison operators, what are they??
hi guys
im a newbie to shell scripting and would appreciate any help possible. my questions will be very straight forward and relatively trivial to most of you.
as the thread title is asking, what are the operators??
i know there's the != and =, but for bourne and c shell, what are the lexical comparison operators?
i read from a website that you could use the < and > as long as you put the forward slash in front of them so that the shell interpreter can identify it as a string operator as opposed to a redirect operator.
this is a snippet of code i've been trying the > and < operators but the tcshell wont work with it. i'musing tcshell while i want to know for bourne and c shell because that's the only shell i have access to at the moment.
anyways here's the code
######################################
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
######################################
basically the shell can't interpret the \< part. any help appreciated.
thanks in advance
10 More Discussions You Might Find Interesting
1. Programming
Hi all,
I have a file like this
ibhib=ere
wefwfl=werfe
sfdes=wef
From this file, i need to get the lefthand side string with respect to the corresponding righthand side string. i.e, I need to get the string "ere" with respect to "ibhib".
But i am stuck with how to compare a string... (1 Reply)
Discussion started by: abey
1 Replies
2. Shell Programming and Scripting
Hello all
im trying to get the Comparison operators from string with out much success
I have :
$myvar = "if (hhhh <= blah.count )" ;
when I do :
if ($myvar =~ m/.*().*/){
.......
}
I keep getting the "=" and not "<="
why ? (3 Replies)
Discussion started by: umen
3 Replies
3. Shell Programming and Scripting
The script will read a bunch of names, and test if it contains "John", but as below apparently ~ does not work, so what is the easiest way to perform string comparison in bash shell script? thanks
...
elif
then
echo "get John"
.... (2 Replies)
Discussion started by: fedora
2 Replies
4. UNIX for Dummies Questions & Answers
Hi Guys
i need to write a script to check the file structure
I have added the the file headers in the configuration file and execute the file at the start of the script.
Now the function
checkFileStructure()
{
echo "Inside the function"
filetocheck=$1
fileheader=$2
if ]
then... (1 Reply)
Discussion started by: Swapna173
1 Replies
5. UNIX for Dummies Questions & Answers
There are a number of comparison operators used in scripting and programming languages, such as the following:
=, ==, ===, !=, =~, <, >, <=, >=, etc
Is there a shortcut name for them, such as one has for as being any capital letter? If not, it would mean that I would have to list them all for a... (2 Replies)
Discussion started by: figaro
2 Replies
6. Shell Programming and Scripting
Apologies for the utter triviality of this question, but we all have to start somewhere! I've also tried searching but this question is pretty vague so I didn't (a) really know what to search for or (b) get many relevant hits to what I did search for.
Anyway, I'm in the process of self-teaching... (1 Reply)
Discussion started by: u5j84
1 Replies
7. Shell Programming and Scripting
continuing from my previous post, whose link is given below as a reference
https://www.unix.com/shell-programming-scripting/171076-shell-scripting.html#post302573569
consider there is create table commands in a file for eg:
CREATE TABLE `Blahblahblah` (
`id` int(11) NOT NULL... (2 Replies)
Discussion started by: vivek d r
2 Replies
8. Homework & Coursework Questions
attempting the hangman program. This was an optional assignment from the professor. I have completed the logical coding, debugging now.
##I have an array $wordString that initializes to a string of dashes
##reflecting the number of letters in $theWord
##every time the user enters a (valid)... (5 Replies)
Discussion started by: lotsofideas
5 Replies
9. Shell Programming and Scripting
hi team,
i want to compare the below string from logs, but its is not working.
if ]; then
echo "restart some process"
fi (4 Replies)
Discussion started by: mfaizan40
4 Replies
10. Shell Programming and Scripting
I have the logic below to look up for matches within the columns between the two files with awk.
In the if statement is where the string comparison is attempted with ==
The issue seems to be with the operands, as
1. when " '${SECTOR}' " -- double quote followed by single quote -- awk matches... (1 Reply)
Discussion started by: deadyetagain
1 Replies