Reputation: 2451
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
Upvotes: 0
Views: 174
Reputation: 3599
It sounds like your script file has windows new lines in it. You can use a shell program dos2unix
to convert it or search and replace, this answer has more details.
^M at the end of every line in vim
Update:
Since you are using notepad++ in windows, you can also choose the end of line character by going Edit -> EOL Conversion
(see Choose newline character in Notepad++). After you've done this you shouldn't have to convert the file every time you copy it over.
Upvotes: 1