I wrote a simple shell script to get the version of Perl modules installed
on a server and I keep receiving the following error:
Can't find string terminator "'" anywhere before EOF at -e line 1.
Here is my script:
#!/bin/sh
#
mod_name="Sub::Uplevel"
tmp1="perl -M$mod_name -e 'print \"\$$mod_name::VERSION\"'"
echo $tmp1
$tmp1
If I just directly run the echo‘d line (perl -MSub::Uplevel -e 'print "$Sub::Uplevel::VERSION"'), it works. Why doesn’t the line work when its run from the variable $tmp1?
In place of just
$tmp1,evalworks:That’s because splitting a variable into words (for arguments) is done strictly by splitting on
$IFS, not the normal input-parsing.evalforces the normal input parsing.How did I figure this out?
Change your
tmp1=line to put anechoin front, and you get:Note that the
'are still there, which you wouldn’t expect. If you write a quick script:and put a call to that in place of echo, you find how the arguments are really split:
So, you can see that’s splitting on spaces, so IFS.