I have to replace blank spaces (" ") of all the values from an array in shell script. So, I need to make an array like this:
$ array[0]="one"
$ array[1]="two three"
$ array[2]="four five"
looks like this:
$ array[0]="one"
$ array[1]="two!three"
$ array[2]="four!five"
Replacing every blank space to another character with a loop or something, not changing value by value.
array=('one' 'two three' 'four five') # initial assignment
array=( "${array[@]// /_}" ) # perform expansion on all array members at once
printf '%s\n' "${array[@]}" # print result
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With