Shell: string1 += string2. How to do this?
!/bin/sh
I would like to do the following operation on strings in shell (concatenate w/ a space): Code:
|
try
Code:
string1=${string1} ${string2} |
Didn't work for me. Here's my code if it helps... Thanks.
Code:
dir_list=`ls -ad */ 2>/dev/null` |
Sorry, I should have known better. /bin/sh isn't taking kindly to the whitespace. It should be something like this
Code:
string1="$string1 $string2" |
Try using an array.
diff: Code:
cleaned_dirs=() Code:
string1 += $string2 Code:
string1=${string1} ${string2} Code:
string1="${string1} ${string2}" |
the array may not really be necessary if he is only building this list in order to pass it as the arguments to a command. Then an array may only complicate the things. This scenario isn't unlikely in a shell script.
To the OP, dawkcid caught my mistake at the same time I did, but you should use the code in my post, as dakwcid's concatenates the strings without a space in between them. |
Quote:
Quote:
|
All times are GMT -5. The time now is 06:17 PM. |