0
#!/bin/bash
maxDate='00000000'
fileDate='20140507'
if [[ $maxDate == '00000000' ]]; then   
  echo "right"
fi
echo $fileDate

This make me really crazy, I have spend whole day to deal with this format stuff. the script is like above it print out unexpected end of file if I delete the last line, it will not print anything which is not correct. I really don't know what wrong with it.

Leon Li
  • 21
  • 1
  • 1
    What is the problem? – igon Nov 11 '14 at 22:08
  • 1
    Check your file with `cat --show-nonprinting filename`. – Cyrus Nov 11 '14 at 22:12
  • 1
    You probably have DOS line endings in your file. This means `then` is actually `then\r`, which `bash` does not recognize as terminating the command list which starts the `if` command, meaning the `bash` parser reaches the end of the file before ever finding the end of the `if` statement. – chepner Nov 11 '14 at 22:21

1 Answers1

1

Remove the DOS line endings from your script with dos2unix. If that is not available, the following can be used:

tr -d '\r' < myscript > myscript.tmp
mv myscript.tmp myscript
chepner
  • 497,756
  • 71
  • 530
  • 681
  • I not fully understand what you mean, like my script file name is text, like you said, I typed tr -d '\r' < text > text.tmp mv text.tmp text. it is not work – Leon Li Nov 12 '14 at 04:58