I have been trying out different solutions to read from a file in linux with no luck at all. My main purpose is to get a http response from an application and store it in a file.
Here is my Code in a shell script file
wget localhost:8080/abc/rest/eventservice/event -O /dev/null -S --quiet 2>&1 | grep "200 OK" > out.txt
while read -r LINE || [[ -n $LINE ]];
do
echo "$LINE";
done < out.txt
After i executed the above sh file i get the below error
'ervercheck.sh: line 6: syntax error near unexpected token `
'ervercheck.sh: line 6: ` done < out.txt
This line wget localhost:8080/abc/rest/eventservice/event -O /dev/null -S --quiet 2>&1 | grep "200 OK"
prints
HTTP/1.1 200 OK
I have also noticed that when i try to look through the file content and type vi out.txt
the content is empty but when i type vi out.txt^M
then content is there.
Please help me as why the execution of shell file gives such error and why i have the ^M at end of my file name