My Values are Equal but They are Not


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting My Values are Equal but They are Not
# 1  
Old 03-02-2010
My Values are Equal but They are Not

Does anybody understand why this is not being interpreted as true.

Script:
Code:
#!/bin/bash

errored=`grep  "errored" new_update_scripts.txt`
echo $errored = "errored"
if [ "$errored" = "errored" ]; then
    echo true
else
    echo false
fi

Output:
Code:
[smackey]$ UpdateScripts

errored = errored
false

# 2  
Old 03-02-2010
Is it errored or "errored" in the "new_update_scripts.txt"?
# 3  
Old 03-02-2010
To start with check the value of $errored

$errored has the value 'errored = errored'

and you are checking if $errored == "errored"

which is false

hence you are getting not equal

HTH,
PL
# 4  
Old 03-02-2010
but it's strange...
i copy and paste scottwmackey's script and execute it, the output is
errored = errored
true
# 5  
Old 03-02-2010
It works for me but does fail if I add a space before or after "errored" in the file. Extra text will show up in the output, but the spaces do not. Maybe that's it?
Code:
# echo "errored" > new_update_scripts.txt
# ./err.sh
errored = errored
true
#
# echo "errored " > new_update_scripts.txt
# ./err
errored = errored
false
#
# echo " errored" > new_update_scripts.txt
# ./err
errored = errored
false
#
# echo "x errored" > new_update_scripts.txt
# ./err
x errored = errored
false
#

edited to add:
Note that if you put the variable in quotes in the echo line, spaces do show up in the output.
Code:
change:
echo $errored = "errored"
to
echo "$errored" = "errored"

# echo " errored" > new_update_scripts.txt
# ./err
 errored = errored
false
#


Last edited by fubaya; 03-02-2010 at 09:43 PM..
# 6  
Old 03-02-2010
of course it will false.
cuz grep will print the line of the string which you search...

CMIIW
# 7  
Old 03-02-2010
It was a space. Thanks all for pointing me in the right direction.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Delete row if both percentage values are equal to zero

Hello, I have compiled a script but I have stucked at one point. Each line contains two pcs of % value and what I want to do is to delete any line if both % values are zero. data: expected output: ow3 should be deleted as both percentage value in related line are equal to zero. ... (2 Replies)
Discussion started by: baris35
2 Replies

2. Shell Programming and Scripting

Deleting consecutive equal values in a file

Hello everyone, I have a requirement as shown below. I need to delete consecutive same values from the source file and give it as output file. Source: a,b,c,d,e,e,f,g Target: a,b,c,d,f,g The repeating value "e" should be deleted from the file completely. How can I achieve this... (14 Replies)
Discussion started by: vamsikrishna928
14 Replies

3. UNIX for Dummies Questions & Answers

Replacing values in a column if they equal a certain value

Hi, I have a tab delimited text file where some lines have the string "NA" in the second column. For these lines, I want to replace NA with the value in the first column, the symbol underscore followed by the value in the fourth column. How do I go about doing that? Thanks! Input: 1 ... (3 Replies)
Discussion started by: evelibertine
3 Replies

4. UNIX for Dummies Questions & Answers

Same strings are not equal

Hi there can anyone help me please. I want to make a program to check if the executable file specified by the user exists in the directory. When I run this program particulary these lines of code does not work: if ("$fi" == "$name") then where It checks whether the specified file is equal to the... (1 Reply)
Discussion started by: FUTURE_EINSTEIN
1 Replies

5. Shell Programming and Scripting

If not equal to then loop

How do I go about amending this simple script that prompts for a yes/no response so that if neither Y or N are entered it will loop back back to the original prompt #!/bin/ksh echo "Enter yes of no" read answer if then echo "You selected yes" elif then echo "You selected no" elif... (5 Replies)
Discussion started by: gmears
5 Replies

6. Shell Programming and Scripting

perl and not equal

Hi all I have this script that i have written in some logging for but i do not want it to log for all option, i have used Getopt::Long 2.11 to allow differnt switches but i only want logging on one type of switch this is my code but it does not like the ne (not equals) i do not wnat the... (7 Replies)
Discussion started by: ab52
7 Replies

7. Shell Programming and Scripting

compare columns for equal values and output a summary

Hi all I am trying to scan a file that has 3 columns: red blue 123351 red blue 848655 red blue 126354 red blue 023158 black white 654896 red blue 650884 I want an output that sums the rows that have matching columns 1 and 2 :wall: red blue has 5 entries black white has 1 entry ... (4 Replies)
Discussion started by: reno
4 Replies

8. Shell Programming and Scripting

while [ $x -ge 50 ] + and equal to zero ; then

while + and equal to zero ; then what to punt instead of phrase and equal to zero. it's bash thank you in advance (1 Reply)
Discussion started by: losh
1 Replies

9. Shell Programming and Scripting

equal to operator

Hi, I have the below script executed arg="dir" if "$arg" = "dir" then echo "true" else echo "false" fi Please let me know what happens in the if command. My output is: dir: dir: No such file or directory false which is not the desired output. When i used test command... (1 Reply)
Discussion started by: anijan
1 Replies
Login or Register to Ask a Question