3

for a variable z

z="I II III IV V VI VII VIII IX X XI XII XIII XIV XV XVI XVII XVIII XIX XX"
echo "${z// /,}"

output is I,II,III,IV,V,VI,VII,VIII,IX,X,XI,XII,XIII,XIV,XV,XVI,XVII,XVIII,XIX,XXOK.

but for

Y=(I II III IV V VI VII VIII IX X XI XII XIII XIV XV XVI XVII XVIII XIX XX)

echo "${Y[@]// /,}"

output is I II III IV V VI VII VIII IX X XI XII XIII XIV XV XVI XVII XVIII XIX XX

0

1 Answer 1

3

Because for

Y=(I II III IV)

if you do:

"${Y[@]// /,}"

All spaces from each element of the array will re replaced by ,.

For example:

$ Y=('I foo' 'II bar' III IV)

$ echo "${Y[@]// /,}"
I,foo II,bar III IV

As you have no spaces in any of the elements of the array, nothing is to be replaced.

1
  • thanks, i was trying to put commas between the array elements there is already an answer for this
    – munish
    May 10, 2016 at 12:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .