trouble executing script in cygwin

Viewed 33

I am completely new to scripting, so take it easy on me, thanks. I use the command 'bash greetings2' and receieve...

greetings2: line 17: unexpected EOF while looking for matching `"' greetings2: line 21: syntax error: unexpected end of file.

  1 #
  2 # greetings2
  3 # greetings program version 2
  4 # A sample program using the if-then-elif construct
  5 # This program displays greetings according to the time of day
  6 # Version2: using the date command format control option
  7 #
  8 echo                   # skip a line
  9 hour=`date +%H`        # store the part of the date string that shows the hour
 10 if [ "$hour" -le 18 ]  # check for the morning hours
 11 then
 12     echo "GOOD MORNING"
 13 elif [ "$hour -le 18 ] # check for the afternoon hours
 14 then
 15     echo "GOOD AFTERNOON"
 16 else                   #it must be evening
 17     echo  "GOOD EVENING"
 18 fi
 19 echo                   # skip a line
 20 exit 0                 # end of the program, exit
1 Answers

your script has CRLF line termination (Windows style). Convert it with d2u filename to LF line termination (Unix style)

d2u belongs to dos2unix package

To verify you can use

$ file greetings2
greetings2: ASCII text, with CRLF line terminators

$ d2u greetings2
dos2unix: converting file greetings2 to Unix format...

$ file greetings2
greetings2: ASCII text
Related