Question on variable naming and assignment...
can i use the value of one variable to generate a name for another variable?
for example i want to use the counter from a "do while" loop to name and define a variable each time the loop executes. for example objectnames1=`ls -a` objectnames2=`ls -a` etc. i don't have a script yet but each time through the loop i intend to cd to a particular directory and then define a variable containing a list of each object in that directory as values. for the rest of the script to work, each variable generated has to be unique, and i can't think of a good way to accomplish this. if using a value from one variable to name another isn't possible, can anyone think of a more elegant solution? i know limited syntax but i'm willing to read up... |
Well you can probably use arrays or have a look at indirect references
|
I'd probably use arrays. But if you have to use them intensively I'd better use another language, like python or perl. That is, unless you have no other option.
I also suggest you to take a look at this: http://mywiki.wooledge.org/ParsingLs |
bash has basic arrays for you. If you have bash 4.0, you can use associative arrays.
For your case Code:
#!/bin/bash Code:
#!/bin/bash |
I agree arrays are probably what you need, but as per i92guboj I'd use Perl instead, judging by the brief description of your problem, and in that case, possibly hashes.
Depends exactly what the rest your requirement is... |
this being my first time shell scripting for any purpose, i didn't even know that bash had support for arrays. thanx everyone for pointing me in the right direction. did some reading... learned the syntax... problem solved.
|
Quote:
|
All times are GMT -5. The time now is 11:52 AM. |