Consider this simple shell script:
#!/bin/sh
fruitlist="Apple Pear Tomato Peach Grape"
for fruit in $fruitlist
do
if [ "$fruit" = "Tomato" ] || [ "$fruit" = "Peach" ]
then
echo "I like ${fruit}es"
else
echo "I like ${fruit}s"
fi
done
When I paste it to a cygwin window it works fine however when I save it as a text file test.sh and run it from the cygwin terminal I'm getting this:
$ ./test.sh
./test.sh: line 4: syntax error near unexpected token `$'do\r''
'/test.sh: line 4: `do
However, if I remove newlines it works:
#!/bin/sh
fruitlist="Apple Pear Tomato Peach Grape"
for fruit in $fruitlist
do if [ "$fruit" = "Tomato" ] || [ "$fruit" = "Peach" ]
then echo "I like ${fruit}es"
else echo "I like ${fruit}s"
fi done
How can I make the script more readable by maintaining new lines in the file, \n
doesn't seem to work.