#!/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?
strange, I cannot comment, but can only "answer".
What I think is that the file is of MS DOS format, when you run the script under ubuntu client on windows, it understand the MS DOS format, and treat it accordingly.
However, on the server side, when you use read LINE to read in the lines in MS DOS format, you will also read in the trailing \\r character.
I bet that's the reason. Try
tr -d '\015' /home/radiare/Desktop/first.txt
first and run your script again.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.