-1
#!/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?

5
  • What is the issue with the "on windows" part in your question title?
    – Sven
    Feb 13, 2013 at 10:43
  • My Ubuntu client is hosted on windows. There is no problem with it. Feb 13, 2013 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, 2013 at 11:10
  • Thanks for the reply. files are replicas So the contents are same. Feb 13, 2013 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, 2013 at 18:10

1 Answer 1

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
1
  • 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 Feb 14, 2013 at 4:55

Not the answer you're looking for? Browse other questions tagged .