You are not logged in.
Let me explain it by an example, say
D1=red ; i=1 ; D$i=blue ; echo $D1
returns
bash: D1=blue: command not found
red
I expect it to return "blue".
So you cannot sign a value to "D$i" by "D$i=blue"
I also tried it another way
D1=red ; i=1 ; echo "D$i=blue" | sh ; echo $D1
returns
red
So...how can I teach it to say "blue"?
Last edited by lolilolicon (2009-06-20 13:52:31)
This silver ladybug at line 28...
Offline
use arrays:
http://tldp.org/LDP/abs/html/arrays.html
don't drink unwashed fruit juice.
i never make predictions, especially about the future.
Offline
ya, works like a charm. I got blue!
$ D[1]=red ; i=1 ; D[$i]=blue ; echo ${D[1]}
blue
This silver ladybug at line 28...
Offline
Thanks, sisco311!
This silver ladybug at line 28...
Offline
Also look here: http://mywiki.wooledge.org/BashFAQ/006
printf -v D$i blue
Offline
Even better! :-)
$ D1=red ; i=1 ; printf -v D$i blue ; echo $D1
blue
This silver ladybug at line 28...
Offline
Also works:
$ D1=red ; i=1 ; read D$i <<< blue ; echo $D1
blue
This silver ladybug at line 28...
Offline