[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-bash] Is there a way to contract y=${x[*]}; "${y// /}" into on
From: |
Stephane Chazelas |
Subject: |
Re: [Help-bash] Is there a way to contract y=${x[*]}; "${y// /}" into one line |
Date: |
Fri, 27 May 2016 22:17:26 +0100 |
User-agent: |
Mutt/1.5.21 (2010-09-15) |
2016-05-27 15:58:07 -0500, Peng Yu:
> Hi, I use the following code to remove spaces from the string of
> "${x[*]}". But it requires two lines. Is there a way to do it in one
> line? Thanks.
>
> x=(a b c)
> y=${x[*]}
> echo "${y// /}"
[...]
"${x[*]}" joins the elements of the x array with the first
character of IFS.
So
IFS=; echo "${x[*]}"
You can also do:
printf %s "address@hidden"
With zsh:
echo $((j[])x}
(j for join).
Or if you want to remove all spaces including those in the
array elements:
echo ${"${x}"// }
--
Stephane