I have a bash script which is currently 700+ lines long. After a particularly long round of editing, it now errors like so:
./run_me.sh: line 693: unexpected EOF while looking for matching `''
./run_me.sh: line 702: syntax error: unexpected end of file
However, there is nothing wrong I can see with line 693. There isn't even a quote on it.
I've tried running bash -x run_me.sh
, and can see the last line run, but there is nothing wrong with that line either (and the code between that line and 693 is, effectively, most of the code).
I can comment out whole swathes of the code, but then I am more likely to see errors due to missing functions, etc, rather than the EOF error I am getting.
So how is someone supposed to find the missing quote, if the line number is reported incorrectly?
(Why is bash's line number reporting so far off, anyway?)
Edit
Incidentally, I found my particular error (by commenting swathes), which was actually a missing }
in a variable expansion at an arbitrary line number nowhere near the line indicated by the error message -- quote-based syntax highlighting did not help here, e.g. with the missing brace in "${MY_ARRAY[@]"
(should be "${MY_ARRAY[@]}"
).
sh -nv <script
as you do. As soon as your error message changes you've found the compound command in which your problem lies. And the line-numbers are fine - each function gets its own. – mikeserv May 25 '15 at 12:20-nv
thing you might get a better idea - the prompts will clue you in. You'll get$PS2
when the shell has at some point begun interpreting a quote or compound layer and has not managed to close that token since the last newline occurred in input. Also try:PS4='LAST EXECLINE: $((LAST+!(LAST=LINENO)))'; set -x
because the lineno's can sometimes get rather funny in subshells. – mikeserv May 27 '15 at 19:28