How to call a array dynamically into a script
Hi All,
I have a script which takes an array as an input to the file. ex: test.ksh -l <array_value> Every time I dont get the same array name. EX: test.ksh -l x ; where x="a b" test.ksh -l y ; where y="c d" I store the value I get in l in varaible myLvalue Now indise my Script I want to run a for loop for the value I get in -l. If I write the for loop as below. I'm getting value x. However I'm expecting the loop to run for a and b. for getLvalue in $myLvalue do echo $getLvalue #I'm expecting a and b to print in sequence done. Please help. |
What you posted is pretty much meaningless to me. I can't follow what you're saying at all. I doubt you're going to get any real help unless you show us some actual code, some real input values, and some background information on what the script is supposed to be doing vs. what it's actually doing.
And please use [code][/code] tags around your code, to preserve formatting and to improve readability. |
I think it is a positional parameter "shift" or $# command for positional parameters.
Quote:
Follows the pseudo-code Code:
K=3 |
Well my first question back would be, what does -l do? I searched through 2 man pages for ksh and could find only one
reference which was to switch uppercase letters to lower (not sure I could see the point here) so I figure it must be something else you are trying to do? Next, you say you are passing in an array and yet you say that x="a b" which is a string with a space in it? Next, assuming that you store the value x in myLvalue, then you would at least need to do an indirect call to see what is stored in x. Finally, You say you wish to loop over an array and yet you refer to your variable as a common variable, ie not of the format ${myLvalue[@]} ... or similar, so how is this looping over an array? |
The OP hasn't been back here since they posted, so they might not return. This thread was only bumped by a spammer..
Edit: In case anyone's wondering, the spammer's post has been removed. |
Sorry ... my bad ... didn't look at that :redface:
|
I bet the threat is dead and I'm actually replying to some advertisers now :-) But the issue posted by the OP made me post, really!
One of the problems with calling your script like this: Code:
./test.ksh -l x ; where x="a b" Your script indeed makes no sense to me, right now. I have no clue what you may want to accomplish and why you would want to do it this way... write a scripting language into a scripting language? You could change things a bit around; assuming -l is the parameter for "array name", you could use -w for your "where" clause: Code:
./test.ksh -l x -w x="a b" |
closed to stop spamming
|
All times are GMT -5. The time now is 03:51 AM. |