Variables in paths dont get displayed

I have a variable embedded in a path, and when I print the path, the variable name gets printed out, and not the actual value. Here is an example.

NODE='database1'
j='/home/log/$NODE/alert$NODE.log'
echo $j

Result that I got : /home/log/$NODE/alert$NODE.log

Result that I expected: /home/log/database1/alertdatabase1.log

Can someone please tell me if I am forgetting something?

Thanks,

Moe

try puting it in this way

NODE=database1
j=/home/log/${NODE}/alert${NODE}.log
echo $j

I did put it the way you told me, and when I ran it I got this

/home/log/${$NODE}/alert${NODE}.log

it printed it the way I wrote it. Same problem.

No chance buddy
which shell are you using??
and paste your code what you tried second time

Its a hybrid shell thats posix compliant.

Here is the code

i='oakdrdb1 oakdrdb2'

for NODE in ${i}
do

j='/home/log/${$NODE}/alert${NODE}.log home/log/${NODE}/evmd/evmd.log'

    echo "\*\*\*\*$NODE****"
    for APATH in $\{j\}
    do
            echo "Current Node: $NODE"
            echo "Current Path: $APATH"
             if [ \`grep "ERROR" $APATH|wc -l\` -gt "0" ];then
                    case $APATH in
                    "/$ORA\_CRS_HOME/log/$NODE/alert$NODE.log"\) echo "Alert log Errors: YES";;
                    "/$ORA\_CRS_HOME/log/$NODE/client/css$i1.log"\) echo "CSSD log Errors: YES";;
                    "/$ORA\_CRS_HOME/log/$NODE/crsd/crsd.log"\) echo "CRSD log Errors: YES";;
                    "/$ORA\_CRS_HOME/log/$NODE/evmd/evmd.log"\) echo "EVMD log Errors: YES";;
                    esac
            else
                    case $APATH in
                    "/$ORA\_CRS_HOME/log/$NODE/alert$NODE.log"\) echo "Alert log Errors: NO";;
                    "/$ORA\_CRS_HOME/log/$NODE/client/css$i1.log"\) echo "CSSD log Errors: NO";;
                    "/$ORA\_CRS_HOME/log/oakdrdb1/crsd/crsId.log"\) echo "CRSD log Errors: NO";;
                    "/$ORA\_CRS_HOME/log/$NODE/evmd/evmd.log"\) echo "EVMD log Errors: NO";;
                    esac
            fi
    done
    echo"";

done

this is what you expecting right??

home/vidya_perl> cat vv
i="oakdrdb1 oakdrdb2"

for NODE in ${i}
do

j="/home/log/${NODE}/alert${NODE}.log home/log/${NODE}/evmd/evmd.log"
echo "$j"
echo "****$NODE****"
done

running the code

/home/vidya_perl> vv
/home/log/oakdrdb1/alertoakdrdb1.log home/log/oakdrdb1/evmd/evmd.log
****oakdrdb1****
/home/log/oakdrdb2/alertoakdrdb2.log home/log/oakdrdb2/evmd/evmd.log
****oakdrdb2****

Yes.....exactly!!!!!

-----Post Update-----

However, I just noticed that your prompt is vidya_perl, so does that mean you are using perl and not unix ?

I am new in unix, so I am not quite familiar with it. Is the way to do this the same on both perl and unix ?

NO no no.....:slight_smile:
thats my directory name where I work its unix only:D

That is not perl. It is just the name of the current directory.

Just change the 1 line in script from

j='/home/log/${$NODE}/alert${NODE}.log home/log/${NODE}/evmd/evmd.log'

to

j="/home/log/${NODE}/alert${NODE}.log home/log/${NODE}/evmd/evmd.log"