Reputation: 1
Question is how to evaluate the complete $variable read from a file.
I have a program combination of python and ksh shell. ksh shell executes a python script which reads xmlfile & returns back a classpath & vairables to export & command to execute.
In my case the xml files looks like the following
1<script>
2 <scriptPath>/home/opapp/apps/ampFeed</scriptPath>
3 <JAVA_HOME>/local/opt/sunjava-1.6.0_01/jre</JAVA_HOME>
4 <classpath>"./properties/prod"</classpath>
5 <classpath>"lib/activation.jar"</classpath>
6 <classpath>"lib/antlr-2.7.6.jar"</classpath>
.......
40 <executionCmd>"$JAVA_HOME/bin/java"</executionCmd>
43 <executionCmd>"-Dtarget.db.properties=/home/opapp/apps/ampFeed/properties/pr od"</executionCmd>
44 <executionCmd>"-classpath"</executionCmd>
..........
</script>
My Shell script is very simple
$0 == XMlFile
typeset -x JAVA_HOME=`${HOME}/scripts/readXmlFile.py -s $0 -e "JAVA_HOME"
typeset -x CLASSPATH=`${HOME}/scripts/readXmlFile.py -s $0 -e "CLASSPATH"
EXECUTION_CMD=`${HOME}/scripts/readXmlFile.py -s $0 -e "CLASSPATH"
export JAVA_HOME
export CLASSPATH
print JAVA_HOME=$JAVA_HOME
print CLASSPATH=$CLASSPATH
print EXECUTION_CMD=$EXECUTION_CMD
$EXECUTION_CMD
Output is the following :-
JAVA_HOME="/local/opt/java7/jre"
CLASSPATH=:"./properties/dev1":"lib/activation.jar":"lib/antlr-2.7.6.jar":"lib/aopalliance.jar"
EXECUTION_CMD="$JAVA_HOME/bin/java" -Dtarget.db.properties=/home/opappqa/apps/Feed/properties/dev1" "-classpath" "$CLASSPATH" "ampFeed.generator.FeedGenerator" "-Xms128M" "-Xmx512M"
line 41: "$JAVA_HOME/bin/java": not found
Question is how to evaluate the complete CLASSPATH & JAVA_HOME
Upvotes: 0
Views: 103
Reputation: 295687
Use eval
to treat the string as code:
eval "$EXECUTION_CMD"
Otherwise, POSIX sh behavior (which ksh follows) runs string-splitting and glob expansion parse phases only, not allowing any portion of the string to be treated as syntax.
That said, see BashFAQ #50 for information on best practices around programmatically generating code. (Some of the advice there is bash-only, but a great deal of it also applies to ksh).
Upvotes: 1