Hi,
Please find my code below.
ps -xef | grep 14766 | awk 'BEGIN{X[1]="java_home=";X[2]="weblogic_home="}
{for(i=1;i<=NF;i++){if($i ~ /-Dplatform\.home|java$/){split($i,P,"=");s=P[2]?P[2]:$i;print X[++a]""s}}}'
echo "java_home="$java_home
echo "weblogic_home="$weblogic_home
Output:
Why does the java_home and weblogic_home show blank when echoed ?
you can't export to a parent process, so the values set in awk (which are awk variables rather than the shell variables you're looking for) are not available when the script terminates.
however you could eval
the output of the awk script
you can't export to a parent process, so the values set in awk (which are awk variables rather than the shell variables you're looking for) are not available when the script terminates.
however you could eval
the output of the awk script
Never used eval
before. Can you let me know how eval can help export the values to the parent process ?
eval $(ps -xef | grep 14766 | awk 'BEGIN{X[1]="export java_home=";X[2]="export weblogic_home="}
{for(i=1;i<=NF;i++){if($i ~ /-Dplatform\.home|java$/){split($i,P,"=");s=P[2]?P[2]:$i;print X[++a]""s}}}')