Double variable substitution


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Double variable substitution
# 1  
Old 06-10-2012
Data Double variable substitution

Code:
$ ABCel='abc@gmail.com'
$ XYZel='xyz@gmail.com'
$ MYel='my@yahoo.com'

$ echo $ABCel
abc@gmail.com
$ echo $XYZel
xyz@gmail.com
$ echo $MYel
my@yahoo.com


I tried 3 variations, but not getting the expected result:

Code:
$ for VAR in ABC XYZ; do echo -e "${VAR}el $MYel"; done
ABCel my@yahoo.com
XYZel my@yahoo.com


Code:
$ for VAR in ABC XYZ; do MAIL=${VAR}el; echo -e "$MAIL $MYel"; done
ABCel my@yahoo.com
XYZel my@yahoo.com


Code:
$ for VAR in ABC XYZ; do MAIL=${VAR}el; echo -e "${MAIL} $MYel"; done
ABCel my@yahoo.com
XYZel my@yahoo.com

Expecting Result:
---------------------
Code:
abc@gmail.com my@yahoo.com
xyz@gmail.com my@yahoo.com

What am I missing here?
Thanks

Last edited by Scrutinizer; 06-10-2012 at 03:55 PM.. Reason: code tags
# 2  
Old 06-10-2012
Try this:eval echo \$${VAR}el
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to use variable with command substitution in variable

For example I have variable like below echo $OUTPUT /some/path/`uname -n` when I try to use the variable OUTPUT like below cd $OUTPUT or cd ${OUTPUT} I am getting bad substituion error message $ cd $OUTPUT ksh: cd: bad substitution $ cd ${OUTPUT} ksh: cd: bad substitution ... (1 Reply)
Discussion started by: rajukv
1 Replies

2. Shell Programming and Scripting

Using echo to print double quotes along with variable substitution

Hi, I am generating html code using cshell, but i am having one problem while printing double quotes, I need to write following code in file. where $var contains list of web address <a href="$var">$var</a> So i am using echo "<a href="$var">$var</a>" > file.html But with this " in... (4 Replies)
Discussion started by: sarbjit
4 Replies

3. Shell Programming and Scripting

Variable Substitution

Hi , I have a variable as follows, Temp=`cat ABC.txt | cut -c5-` This will yeild a part of the date. say , 200912. I would like to substitute this variable's value in a filename. eg: File200912F.zip when i say File$TempF.zip , it is not substituting. Any help ? Thanks in... (2 Replies)
Discussion started by: mohanpadamata
2 Replies

4. Shell Programming and Scripting

How do I perform double substitution in bash?

#!/bin/bash #set -x MAX=255 FILE=$1.dns_list #declare -a d_arr if then echo "Usage: `basename $0` network" echo " e.g.`basename $0` 1.1.1" exit fi echo "Remove file $FILE..." rm $FILE for (( i = 1; i < $MAX; i++ )) do PARSE=$(host $1.${i}) ... (3 Replies)
Discussion started by: flee
3 Replies

5. Shell Programming and Scripting

Sed variable substitution when variable constructed of a directory path

Hello, i have another sed question.. I'm trying to do variable substition with sed and i'm running into a problem. my var1 is a string constructed like this: filename1 filerev1 filepath1 my var2 is another string constructed like this: filename2 filerev2 filepath2 when i do... (2 Replies)
Discussion started by: alrinno
2 Replies

6. Shell Programming and Scripting

double substitution

Hello, I would like to dual subtitutes variables. I tried $serv="combo" combo_TYPE="mop" TYPENAME="$serv_TYPE" Now, I'd like to get "mop" from TYPENAME echo "${${TYPENAME}}" I have a bad substitution error :) (1 Reply)
Discussion started by: pppswing
1 Replies

7. Shell Programming and Scripting

Double Substitution variables in ksh

Hi I have a variable whose value is like this i=/test/test1/test2/myfile.cd.070505123457 i would like to have the value of myfile.cd stored into another variable my attempt is test=${i##*/} ;echo $test ##and i get myfile.cd.070505123457 since what i wnat is myfile.cd i try this... (19 Replies)
Discussion started by: xiamin
19 Replies

8. Shell Programming and Scripting

Variable Substitution

I have run into a wall with my iptables firewall scripting. I am blocking all of the private side IP addresses on the WAN interface on systems running NAT. However, if the system is not running NAT and needs to allow access to the local LAN on the WAN interface, I need to block all but one of... (2 Replies)
Discussion started by: garak
2 Replies

9. UNIX for Dummies Questions & Answers

double variable substitution

Hi, I want to substitute variable in sed using combination of name and var_$name: name=Tom var_$name=1 sed -n "${var_"$name"}"p < myfile but it doesn't work, do you know what's wrong ? Thanks (1 Reply)
Discussion started by: asal_email2
1 Replies

10. UNIX for Advanced & Expert Users

Substitution in a variable

Hey All, I'm trying to clean up a variable using sed but It dosn't seem to work. I'm trying to find all the spaces and replace them with "\ " (a slash and a space). For Example "Hello World" should become "Hello\ World". But it does nothing. If I put it directly into the command line it works... (3 Replies)
Discussion started by: spragueg
3 Replies
Login or Register to Ask a Question