Accessing arrays position in a split string
Hi,
I've a string "this.is.a.name", and I would like to put it in an array. But, I've like to print the output of the array as: Code:
echo ${array[0]} Code:
STR="this.is.a.name"; I've searched over the manuals and the web, and I couldn't find a solution for my case. How can I do that? Thanks, |
You're close, but you need to add another set of () when you assign the array.
Code:
#!/bin/bash |
That's right Guttorm, but what's the meaning of the outer parenthesis of "($(echo $STR | tr "." " "))"?
|
Without the outer, the variable named array simply gets the value of "this is a name". The outer means it will be an array. The difference is the same as
array="this is a name" array=(this is a name) |
Now I get it. Thanks for the help.
|
All times are GMT -5. The time now is 04:25 AM. |