|
Author |
Message |
|
|
Posted Jan 05, 2009 at 12:04:55 PM
Subject: Bash script dynamic file naming
Hi All,
This is my first post, im hoping someone can shed some light into this!
I need to create a variable name on the fly then store information from a file to it e.g.
--------------------------------------------------
#Get Details from ini file
tmp=`cat "config.ini" | grep NumberOfLoadables=`
#Store info
arr_Load${x}_Type${j}=`echo ${tmp#*=}`
--------------------------------------------------
But, when i run the script i get an error like this..
[b]arr_Load1_Type1=osver_db.xml: command not found[/b]
I think the problem is with how "arr_Load${x}_Type${j}" is being create! I need to have the two indexes in the variable name and dynamically.
Does anyone have any ideas?
|
thobbs
Joined Oct 12, 2008 Posts: 238
Location:Texas!
Other Topics
|
Posted:
Jan 05, 2009 7:24:51 PM
Subject: Bash script dynamic file naming
I'm pretty sure you can't dynamically name a variable. Are you trying to create a pseudo 2D array of arr_Load_Type variables? Why do you not just create an actual 2D array? See here: [url]http://tldp.org/LDP/abs/html/arrays.html[/url], especially the section on "nested arrays".
[Modified by: thobbs on January 05, 2009 01:29 PM]
|
blinky
Joined Jan 08, 2009 Posts: 51
Other Topics
|
Posted:
Jan 08, 2009 6:26:27 PM
Subject: Bash script dynamic file naming
I put "NumberOfLoadables=abcde" into a config.ini
Then tried tried:
tmp=`grep "NumberOfLoadables=" config.ini`
x=1
j=1
eval "arr_Load${x}_Type${j}=${tmp#*=}"
echo $arr_Load1_Type1
and "echo $arr_Load1_Type1"
prints abcde
also
eval echo "\$arr_Load${x}_Type${j}"
prints abcde
Not sure if that will help but I think you need to play with "eval" and use indirection to make it work (hope that makes sense).
In a world without walls and fences, who needs Windows and Gates
|