Dear All, In some cases, bash gives exceptionally unhelpful error messages, of the sort "Unexpected end of file". This is next-to-useless as a debugging aid, since there is no way to find out where the error really lies.
I'm using bash version: bash-3.2-7mdv2008.1 Here are 2 shell scripts with examples. bug-example.sh demonstrates the problem. bug-example2.sh is where bash gets it right. Thanks very much, Richard [EMAIL PROTECTED] ~]$ cat bug-example.sh ------------------------------------------------------------- #!/bin/bash #This is an example of bash being unhelpful with syntax errors. function usage () { cat <<-EOT This help text is a heredoc EOT #NOTE that the line above contains a trailing TAB, and # is therefore NOT valid as the end of the heredoc. } usage echo "A long script goes here..." echo "Many lines later..." exit 0 #This script generates the following error: # ./bug-example.sh: line 37: syntax error: unexpected end of file #That is really not helpful, since there's no way to track down where #the error started. Line 37 is not interesting. What we need is a #warning about line 6. #At a minimum, we should get this error message: # ./bug-example.sh: line 37: syntax error: unexpected end of file # (started at line 6) #Better, would be this error message: # ./bug-example.sh: line 6: syntax error: unterminated heredoc. #An additional buglet is that in fact, trailing whitespace after #a heredoc terminator should probably be ignored anyway? ------------------------------------------------------------- [EMAIL PROTECTED] ~]$ cat bug-example2.sh ------------------------------------------------------------- #!/bin/bash #This is an example of bash being *helpful* with syntax errors. X=$((1 + 2) #NOTE missing trailing ). echo "X is $X" #Should print 'X is 3' echo "A long script goes here..." echo "Many lines later..." exit 0 #This script gets it right with the error message. # ./bug-example2.sh: line 5: unexpected EOF while looking for # matching `)' # ./bug-example2.sh: line 20: syntax error: unexpected end of file #So, we can quickly find the bug. -------------------------------------------------------------