Okay, so I'm stuck working with a shell script that needs to use
eval (I know, I know, ultimate evil etc…) however I'm having difficulty debugging some of the line numbers being thrown out by errors.
script.sh: eval: line 315: syntax error near unexpected token `('
The line definitely doesn't correspond to line 315 in
script.sh as that's entirely unrelated to the error. So I threw in random new-lines to figure out which line is originating the error, and as you'd expect it's a line with an
However, when I output the code being passed into the
eval, it doesn't even contain 200 lines, let alone 315+! So what's going on here? Is there a way to usefully use the line numbers being reported, are they somehow based on the position at which the
eval statement is run or something? I don't seem to be able to see a pattern thus far.
If I could I'd replace all the
eval statements, but unfortunately the code being passed is dynamically generated (not from user-input, don't worry!), and needs to be able to manipulate variables in the same scope as the rest of the script, which seems to preclude using
echo "$commands" | sh or similar alternatives. I also have the issue of compatibility, and unfortunately as evil as it is
eval is widely available.