Having trouble with echoing strings in round robin fashion
Hi all,
i am totally new to shell scripting and the first script which i am trying is to echo string variables in round robin manner. the code which i am trying is Code:
#!/bin/bash Code:
0 Help plz... |
Try this:
Code:
#!/bin/bash |
Thanks for the reply, but the problem still stands.
Well actually the problem which i have described is only subset of the whole program. The actual code is Code:
#!/bin/bash |
Here is what I did to get it working. It's not the only way but it will work :)
Code:
#!/bin/bash |
Use indirect variable reference as in:
Code:
#!/bin/bash |
yeah, this works fine. Thanx :)
but can you explain the significance of the ! inside the curly brackets.:confused: |
It is the syntax introduced in Bash version 2 for the indirect variable reference:
Code:
${!varname} |
Quote:
Code:
#!/bin/bash Code:
create set_0 $((expression)) is a different way of doing `expr expression`. At any rate, I think the heart of the problem you are having is that you are trying to emulate using an array. Since BASH has array variables, it is far easier (and cleaner) to just use an array. Basically, you can define array variables in bash with either Code:
variable[subscript]=value Code:
variable=(value1 value2 value3 ...) Code:
echo $variable[subscript] |
All times are GMT -5. The time now is 02:33 AM. |