Results 1 to 3 of 3
I'm writing a bash script and I need to add a : (colon) before each of the elements of my array when I list the array elements. For the sake ...
- 02-03-2009 #1Just Joined!
- Join Date
- Nov 2006
- Posts
- 2
Manipulating array output/string manipulation
I'm writing a bash script and I need to add a : (colon) before each of the elements of my array when I list the array elements. For the sake of being able to reuse the variables easily in other parts of my script, I don't want to add the colons to the array elements when I define the array. I also would prefer not to loop through the elements by getting a count, so as to keep it simple and would prefer to just use the * to get my elements.
Here is my desired resultCode:#PATHS I WOULD LIKE TO USE MYPATHS=('/etc' '/home' '/var/www') echo ${MYPATHS[*]}
:/etc :/home :/var/www
I'm sure this is easy, but it's driving me crazy. The smaller/simpler the command the better as others have to read and edit the script. All suggestions are welcome though. Thanks for the help.
- 02-03-2009 #2Linux Newbie
- Join Date
- Jul 2008
- Posts
- 181
If you don't mind ugliness, use this:
Code:${MYPATHS[*]/#/:}
- 02-04-2009 #3Just Joined!
- Join Date
- Nov 2006
- Posts
- 2
That's what I was thinking I would have to do. I would prefer to just add a character for simplicity sake, but replacement will have to do for now. Thanks.


Reply With Quote