The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Special Forums > UNIX and Linux Applications
.
google unix.com



UNIX and Linux Applications Discuss UNIX and Linux software applications. This includes SQL, Databases, Middleware, MOM, SOA, EDA, CEP, BI, BPM and similar topics.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
String comparison 46019 Shell Programming and Scripting 2 07-10-2009 02:56 AM
String Comparison squardius Shell Programming and Scripting 3 04-30-2009 11:28 AM
Help with String Comparison hypnotic_meat Shell Programming and Scripting 2 04-24-2009 08:48 AM
string comparison fedora Shell Programming and Scripting 2 01-03-2007 03:20 PM
String Comparison abey High Level Programming 1 10-19-2005 12:08 PM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-12-2009
MNG MNG is offline
Registered User
  
 

Join Date: Oct 2009
Posts: 2
Need Help on String Comparison

Hi ,
My requirement is to read from a file into a variable.
I need to check if the variable is equal to string "no rows selected".
The sh script snippet is as follows:
Code:
 
file=/data/lpgtwo/home/nikhilp/TriggerNames.txt
echo $file
var=`cat $file`
echo $var
if [  $var == "no rows selected" ]
then
        echo "No Triggers to disable"
        exit 1;
fi
On the execution of the above I get test: unknown operator rows

I am new to shell script. Can some one please let me know where am I going wrong.

Last edited by pludi; 10-12-2009 at 09:42 AM.. Reason: code tags please...
  #2 (permalink)  
Old 10-12-2009
thegeek thegeek is offline
Registered User
  
 

Join Date: Apr 2009
Location: /usr/bin/vim
Posts: 436
It is not '==', it is '=' to compare a string in bash.
Code:
#!/bin/bash

var="test";

if [ $var = "test" ]; then
    echo "Matched..";
else
    echo "Not matched ..";
fi
  #3 (permalink)  
Old 10-12-2009
MNG MNG is offline
Registered User
  
 

Join Date: Oct 2009
Posts: 2
I am using sh script not bash.
I tried as you suggested still getting the same error
  #4 (permalink)  
Old 10-12-2009
fpmurphy's Avatar
fpmurphy fpmurphy is offline Forum Staff  
Moderator
  
 

Join Date: Dec 2003
Location: Florida
Posts: 1,912
Quote:
I am using sh script not bash
bash is often (unfortunately) linked to /bin/sh and/or /usr/bin/sh.

What operating system are you using?
What does echo $BASH_VERSION return?
What does echo $(KSH_VERSION} return?
What does echo ${.sh.version} return?
Sponsored Links
Reply

Bookmarks

Tags
sh shell, string comparision, unix

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 06:40 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0