[bash] indirect array reference to array with values containing spaces
This _almost_ works. I just can't quite get it to honor the spaces.
Code:
#!/bin/bash |
You could use IFS to do this... http://tldp.org/LDP/abs/html/internalvariables.html (Note change to PROFILE_ONE)
Code:
#!/bin/bash |
Thanks,
One oddity about this though, is that newlines still work as a separator. Can anyone explain this? Just for anyone coming across this, you only need to change the IFS when going over the loop. Also you need to check for some blank entries: Code:
#!/bin/bash |
Actually, I still have a problem with this. It has to do with quoted strings:
Code:
#!/bin/bash |
The code can be tightened up a little like this, assuming IFS starts with the default value (and legibility is not a prime concern!)
Code:
#!/bin/bash |
Quote:
|
The example above displays as:
Code:
setting1 Code:
setting1 |
But that is not the content of PROFILE_ONE when it is initialised with
Code:
PROFILE_ONE=( |
I don't know what you mean by that. If I set IFS=, then I expect for that declaration of PROFILE_ONE to have 3 items, not 5.
|
Hadn't the IFS=, been moved after the array initialisation? And anyway setting IFS=, and then using "," as an array element separator doesn't work:
Code:
c@CW8:~$ IFS=, |
All times are GMT -5. The time now is 06:49 AM. |