You are not logged in.

#1 2009-06-20 13:20:35

lolilolicon
Member
Registered: 2009-03-05
Posts: 1,722

[SOLVED][bash]How to sign the value that a variable got signed to?

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

#2 2009-06-20 13:26:51

sisco311
Member
From: Romania
Registered: 2008-05-23
Posts: 112

Re: [SOLVED][bash]How to sign the value that a variable got signed to?


don't drink unwashed fruit juice.
i never make predictions, especially about the future.

Offline

#3 2009-06-20 13:49:58

lolilolicon
Member
Registered: 2009-03-05
Posts: 1,722

Re: [SOLVED][bash]How to sign the value that a variable got signed to?

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

#4 2009-06-20 13:51:23

lolilolicon
Member
Registered: 2009-03-05
Posts: 1,722

Re: [SOLVED][bash]How to sign the value that a variable got signed to?

Thanks, sisco311!


This silver ladybug at line 28...

Offline

#5 2009-06-20 14:17:46

Procyon
Member
Registered: 2008-05-07
Posts: 1,819

Re: [SOLVED][bash]How to sign the value that a variable got signed to?

Also look here: http://mywiki.wooledge.org/BashFAQ/006

printf -v D$i blue

Offline

#6 2009-06-20 14:54:48

lolilolicon
Member
Registered: 2009-03-05
Posts: 1,722

Re: [SOLVED][bash]How to sign the value that a variable got signed to?

Even better! :-)

$ D1=red ; i=1 ; printf -v D$i blue ; echo $D1
blue

This silver ladybug at line 28...

Offline

#7 2009-06-20 15:00:04

lolilolicon
Member
Registered: 2009-03-05
Posts: 1,722

Re: [SOLVED][bash]How to sign the value that a variable got signed to?

Also works:

$ D1=red ; i=1 ; read D$i <<< blue ; echo $D1
blue

This silver ladybug at line 28...

Offline

Board footer

Powered by FluxBB