Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.
#!/bin/bash

# Reading

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

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

echo "second file read started"
cat /home/radiare/Desktop/second.txt | while read LINE

do
echo $LINE
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
    
Are you certain that /home/radiare/Desktop/first.txt and /home/radiare/Desktop/second.txt are respectively identical on both of the systems? To search for errors, add an echo "Before if: $LINE" before the if clauses. Also, instead of cat file | while ... done, the "right" way is while ... done < file. –  Daniel Andersson Feb 13 '13 at 10:53
    
ok, well I will try that. But you said some thing about while...done<file can you please give some sample code. –  user1597811 Feb 13 '13 at 10:58
    
That was the sample code :-) . Instead of piping the cat file command into the beginning of the while loop, add < file at the end of the loop. It will not make any real difference in practice, but it is the "correct" way to do it. See Wikipedia. Don't get hung up on this point, though. –  Daniel Andersson Feb 13 '13 at 11:05
    
Thanks for the reply I will try that approach aswel,for now I put echos in the above code like I modified the above code posted. The output is (false, second file read started) This means that it is reading first file properly but not going into if loop and it is not at all reading second file. Any idea why this is happening. –  user1597811 Feb 13 '13 at 11:15
    
Since we who read the question does not now what is in the input files, we can't easily judge what the output should be. Perhaps paste the input files into your question. –  Daniel Andersson Feb 13 '13 at 11:27
show 1 more comment

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.