You are not logged in.
Pages: 1
Ok, quick question that Google has failed to answer.
I have a for loop in which each $i is the name of a variable that I defined before. If the user wants to. They can change it from the default value specified before. The problem is that I can edit the variable with $i=$input . I there any way to get around Bash's prejudice against variable assaignment of expanded names.
Last edited by Mardoct (2009-11-24 05:45:33)
The human being created civilization not because of willingness but of a need to be assimilated into higher orders of structure and meaning.
Offline
If I understood you correctly, I think eval is you answer. Have a look at this.
#!/bin/bash
progressref () { #$1=name of variable
y=\$"$1" # Name of variable
localvar=`eval "expr \"$y\" "` # localvar set to contents of named variable
result="xxx"$localvar
eval "$1=\"$result\"" # named variable set to result
}
testvar="test"
progressref testvar
echo $testvar
Offline
Ahh, worked perfectly. Thanks.
The human being created civilization not because of willingness but of a need to be assimilated into higher orders of structure and meaning.
Offline
@IgnorantGuru:
I think you just lived up to the 2nd part of your handle!!
That's cool!
Offline
@perbh
Those rare occassions are always nice, especially with so much of the first part going on!
It is a cool Bash thing almost like pointers - handy for setting a whole bunch of named variables from command line arguments too, without having explicit code for each one.
Offline
Pages: 1