Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.
#!/bin/bash

# Reading

cat /home/radiare/Desktop/first.txt | while read LINE

do
if [ "$LINE" == "false" ]; then
echo "Inside first loop"
break
fi
done

cat /home/radiare/Desktop/second.txt | while read LINE

do
if [ "$LINE" == "false" ]; then
echo "Inside second loop"
break
fi
done

In ubuntu client, I could able to execute this script and echo inside if statements are properly working. I did the same thing in ubuntu server it is not going inside the if statement. only difference is I run using sudo on the server.

Any suggestions?

share|improve this question

closed as off topic by Sven, Tom O'Connor, Khaled, Stefan Lasiewski, voretaq7 Feb 13 '13 at 18:10

Questions on Server Fault are expected to relate to professional server, networking, or related infrastructure administration within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

    
What is the issue with the "on windows" part in your question title? –  Sven Feb 13 '13 at 10:43
    
My Ubuntu client is hosted on windows. There is no problem with it. –  user1597811 Feb 13 '13 at 10:45
    
I would suspect the content of the files is different on your two machines. Can you replicate this problem with echo rather than cat? (Assuming that the script is exactly the same on both machines.) –  Ladadadada Feb 13 '13 at 11:10
    
Thanks for the reply. files are replicas So the contents are same. –  user1597811 Feb 13 '13 at 11:38
1  
We can't really debug this for you -- you need to do the legwork here. Your best bet is to print $LINE before each if statement and see what's going on. (Also I have no idea what you mean by "ubuntu client" - do you mean Ubuntu Desktop Edition as opposed Server or Cloud editions?) –  voretaq7 Feb 13 '13 at 18:10

1 Answer 1

Try adding -x after the shebang line so it looks like this: #!/bin/bash -x. The output will look like this:

+ read LINE
+ cat /home/radiare/Desktop/first.txt
+ '[' true == false ']'
+ read LINE
+ '[' true == false ']'
+ read LINE
+ '[' false == false ']'
+ echo 'Inside first loop'
Inside first loop
+ break
+ read LINE
+ cat /home/radiare/Desktop/second.txt
+ '[' true == false ']'
+ read LINE
+ '[' true == false ']'
+ read LINE
+ '[' false == false ']'
+ echo 'Inside second loop'
Inside second loop
+ break

Note that I created a file with these contents for this test:

true
true
false
true

second.txt was a symlink pointing to first.txt.

I also ran it with sudo and got identical results.

Alternatively, you could add an else clause to see what the input looked like when it didn't descend into the if statement:

if [ "$LINE" == "false" ]
then
  echo "Inside first loop"
  break
else
  echo "LINE is $LINE"
fi
share|improve this answer
    
value=$(</var/www/symmetric-ds-3.1.6/bin/my_mon.txt) if [ "$LINE" == "false" ]; then echo"Inside loop" fi This worked for me. Culprit is cat I guess –  user1597811 Feb 14 '13 at 4:55

Not the answer you're looking for? Browse other questions tagged or ask your own question.