I have done a shell script that gets the output of a .jar file and assign in to a variable.
rewards_generator.sh
APP_ROOT=/home/testApps/
JAR=${APP_ROOT}ClusterGenerator/generator.jar
#get clusters
clusters=$(loadClusters $1)
for i in `echo $clusters | sed 's/,/ /g'`
do
#pull cluster records from database and save query return status to $x
x=$(/usr/IBM/WebSphere/ProcServer/java/bin/java ${JAR} ${i/-/_} 2>&1)
done
Basically, what I’ve done to the java app is to System.out.print the query return status. Then used the 2>&1 in bash in order to get into the output stream and assign the value to a shell script variable.
Now how can I get the return value of a perl script and assign it to a shell script variable? Is it the same as the one I’ve done above or is there any other approach to do this?
You can use backticks to record the output of an external command in a bash script.
Here’s a simple example: