View Single Post
  #1   (View Single Post)  
Old 21st September 2010
cq04cw cq04cw is offline
New User
 
Join Date: Sep 2010
Posts: 5
Unhappy is there difference between two variations of sh command substitution?

PHP Code:
set -x     # open xtrace option to help for debugging
aa=AAAA   # set $aa to AAAA
aa=AAAA
_var=aa    # set $_var to aa
_var=aa
$ echo ${aa}
+ echo 
AAAA
AAAA
$ echo ${_var}
+ echo 
aa
aa
$ echo ${b}
+ echo

b=$( eval echo \$$_var )   # this method as expected
+ eval echo '$aa'
+ echo AAAA
b=AAAA
$ echo ${b}
+ echo 
AAAA
AAAA
b=`eval echo \$$_var`    # this method not as expected ,should it be same result as previous method? 
+ eval echo 1401_var
+ echo 1401_var
b=1401_var
$ echo ${b}
+ echo 
1401_var
1401_var 

ref to "http://www.freebsd.org/cgi/man.cgi?query=sh&manpath=FreeBSD+8.1-RELEASE" command substitution section
environment ===
FreeBSD abc.xyz.com 8.1-RELEASE FreeBSD 8.1-RELEASE #0: Mon Jul 19 02:55:53 UTC 2010 root@almeida.cse.buffalo.edu:/usr/obj/usr/src/sys/GENERIC i386
Reply With Quote