1833154 Members
2959 Online
110051 Solutions
New Discussion

Script Help

 
SOLVED
Go to solution
Glynn Aherne_1
Advisor

Script Help


Hi Folks,

We have various environment variables set ie $mtrack_dump, $matrack_asset etc.

I'm trying to write a script that takes mtrack as an argument and then within the script add eihter the asset or dump part of the string. Then I'm trying to reference the value of the enviroment variable

i.e.

echo $"$1" gives $mtrack_asset

instead of the value of $mtrack_asset

Thanks in advance

Glynn
6 REPLIES 6
Justo Exposito
Esteemed Contributor

Re: Script Help

Hi Glyn,

Try:

echo "$1"
or
echo "${1}"

Regards,

Justo.
Help is a Beatiful word
John Palmer
Honored Contributor
Solution

Re: Script Help

Hi,

You need to use the shell's 'eval' command to achieve this. Check it out in man sh-posix.

e.g.

mtrack_asset=

$1 is "mtrack"

eval echo \$${1}_asset

will display the contents of mtrack_asset.

Regards,
John
Glynn Aherne_1
Advisor

Re: Script Help


Justo,

echo "$1"
or
echo "${1}"

will only give me the string I'd supplied to the script

mtrack

Trond Haugen
Honored Contributor

Re: Script Help

It may not be cresious but:
echo $"$(echo $1)"
should do the work.

Regards,
Trond
Regards,
Trond Haugen
LinkedIn
Glynn Aherne_1
Advisor

Re: Script Help


John,

Perfect just what i needed

Thanks,

Glynn
Justo Exposito
Esteemed Contributor

Re: Script Help

Sorry Glynn, I missunderstand you.

Regards,

Justo.
Help is a Beatiful word