string comparison not working

string comparison not working

Post by Dave » Sun, 06 Jul 2003 12:19:13



Hello,

I'm having problems with string comparison. One of the strings is a
command argument passed to the script as $1. The other string is
a word extracted from a file:

var=`awk '/WORD/{print $3}' file`

if [ "$1" = "$var" ]; then
   echo "strings are identical"
else
   echo "strings are NOT identical"
fi

Here is what happens when I run the sript in debugging mode: set -x

++ awk '/WORD/{print $3}' file
+ var=argument
 ']'' argument = argument
+ echo strings are NOT identical
strings are NOT identical
+ set -

Even though both strings are the same I always get the "strings are NOT
identical". I use bash 2 under Linux. Thank you.

Dave

 
 
 

string comparison not working

Post by Stephane CHAZELA » Sun, 06 Jul 2003 16:38:48


[...]
Quote:> var=`awk '/WORD/{print $3}' file`
[...]
>  ']'' argument = argument

[...]

"file" is a DOS text files with CRLF line terminators instead of
Unix LF ones. Use dos2unix or "tr -d '\15' before processing if
with awk.

--
Stphane

 
 
 

1. Bash string comparison not working

I want to grab a copy of the website and store the md5 signature of the
index page in a file I am calling "journal.txt". Every few hours, I want to
fire the script and grab a fresh copy of the page. If the signature of the
page does not match the last entry in the journal, I will tell it to send me
an email. The problem is that I can't get it to recognize that the signature
is different. Echoing both variables to the screen shows that the correct
values are being stored in each variable, so I know it's playing with the
right strings. Does anybody know why $OLDHASH and $NEWHASH are being treated
as the same even when they are different? Is it possible that text strings
need some kind of special treatment?

Here's the part that's giving me problems:

----------------begin--------------------
!# /bin/bash

wget http://www.website.com

OLDHASH=`tail -1 journal.txt`
echo "The old signature is $OLDHASH"

NEWHASH=`md5sum index.html`
echo "The new signature is $NEWHASH"

md5sum index.html >>journal.txt
mv index.html index.html-$(date +%y%m%d%H%M)

  if [ "$OLDHASH"=="$NEWHASH" ] ; then
       echo "No changes detected"
  fi

------------------end------------------------

Thank You for your time
--
Julie Ventimiglia

2. ppp in linux

3. Riddle me this - when is a ksh string not a string?

4. help me again!

5. string comparison problem

6. LAM: heterogeneous cluster computing on UNIX

7. String Comparison

8. Running an Editor for a client connection

9. Multiple String Comparison in Ksh.

10. string comparisons

11. Sting Comparisons How do i find if one string contains another

12. string comparison

13. AWK string comparisons