calling a aliased variable

Issue:

i have variable A which is an alias for variable B which is equal to "THIS IS A TEST"

when every i echo variable A i only get the alias name for variable B, NOT the contents of variable B.

HOSTNAME# echo $TESTIT
+ echo THIS IS A TEST
THIS IS A TEST

HOSTNAME# ls -l
total 16
-rw-r--r--   1 user group        6 Jul 15 13:58 TEST.IT


HOSTNAME# for i in `ls`; do
DOH=`echo $i|awk -F. '{ print "$"$1$2 }'`
echo $DOH
done
$TESTIT


HOSTNAME#

From your first statement:

I set A to equal value of B - echo $A - get nothing (B was nothing)
Set B and then A again - and the value shows up.
$ A=$B
$ B="This is a test"
$ echo $A

$ A=$B
$ echo $A
This is a test

As far as the code:
I don't see why you get two $TESTIT at the end. When I ran it, it only writes it out once ($TESTIT). I believe you are attempting to cat the file (show the contents of the file) Could you explain more of what you are attempting to do? What shell you are using and OS+version?

OS: SOL 8
Shell: ksh

I have a list of files in a directory.

ie:
test.it

test.u

it takes this list and strips off the "." so i get testit, testme, testu.

these are actually variables that are sourced in from another file.
(i am sorceing it correctly)

so if you do a echo on those variables you get soemthing like the following:

echo $testit
THIS IS TEST IT

echo $testme
THIS IS TEST ME

echo $testu
THIS IS TEST U

. ./source-file
for i in `ls`; do
DOH=`echo $i|awk -F. '{ print "$"$1$2 }'`
echo $DOH
done

this only prints out the word $testit/$testme/$testu not the contents of what the variable is supposed to be.

now if by hand i say

doh=$testme
echo $doh
(it will then print the correct output) but useing the awk statement to fill the contents of $doh does not seem to work.

. /var/adm/scripts/dfh

INDIR="/drop"
ARCHIVEDIR="/archive_messages/exported"
OUTDIR="/export/manual"
SENDDIR="/export/mbi"
FUUSER="user"
FUGROUP="group"
OPENFILE=`/usr/local/bin/lsof +d ${INDIR}|grep ${FUUSER}|awk -F"/" '{ print $4 }'`

set -x

if [[ -d ${INDIR} ]] ; then
        cd ${INDIR}
        for file in `ls` ; do

DFHNAME=$`echo $file | awk -F. '{ print $1 $2 }'`

                if [[ $file != ${OPENFILE} && `tail -1 $file|awk '{ print $1 }'` = "97" ]]; then
                        chown $FUUSER:$FUGROUP $file
                        echo "$DFHNAME" > /$OUTDIR/$file.tmp
                        cat /$INDIR/$file >> /$OUTDIR/$file.tmp
                        rm -f $file
                        cp -p  /$OUTDIR/$file.tmp $ARCHIVEDIR/$file.`date +%Y%m%d%H%M%S`
                        mv /$OUTDIR/$file.tmp $SENDDIR/$file.`date +%Y%m%d%H%M%S`
                                        fi
        done
fi

Realize you are not setting DOH to a value of another variable - you are setting it to "$" $1$2. This is two different things. Just as I stated earlier, if B is nothing setting A=$B give you nothing.

You are stating DOH to be equal to a string "$TESTIT" not a value of the variable $TESTIT. I'm not sure the work around (I've been looking...). Will get back to it tomorrow if no one else has (must go home as the EOD is here).

If I'm understanding this correctly, try this:

# b="this is a test"
# a="b"
# eval echo \$$a
this is a test

gsatch: i dont have the eval command. i will see if i can download it.

RTM: your help is much appricated. Yes, shortyly after i posted last night i went home also. and your answer makes complete sense; something i had not thought of.

I tried the eval command - Solaris 2.6 showed the following on the man page: eval - Evaluate a Tcl script. It didn't work and I'm not sure it would unless this was a Tcl script. But it was worth a shot. It also seems to me I have heard of this type of fix before - I just can't remember what/where. Will look at the script in a bit and post back.

'eval' is a built-in command in the borne, korn and c shells. Basically, it evaluates and executes whatever follows it as a command. In my example, '$a' is replaced by it's contents, or "b" so that the 'eval' line becomes the equivalent of 'echo $b'.

I did find in man -s 1 eval - which is what I was thinking about originally - don't know where the link to tcl came from (now I have a situtation to look into!).

Anyway, using the eval DOES work as suggested by gsatch. I put it into the test script I was running and it echos out the variable value.

#!/bin/ksh
for i in `ls`; do
DOH=`echo $i|awk -F. '{print $1$2}'`
echo "$DOH"
eval echo \$$DOH
done

You should not need to 'download' eval - it's a built-in function of the shell (which is why you may not find it with 'which eval').

Post back if you have problems with it - Way to go gsatch!

i knew you guys were a couple of "cool guys" (puts on my steve martin voice from SNL)

thanks much for the help. it does exactly what i want it to do. and i get the spaceing i needed also.

eval echo \"\$$DFHNAME\"