Skip to main content
deleted 22 characters in body
Source Link
guest
  • 2.2k
  • 6
  • 11

There is the parameter expansion ${name:#pattern} (pattern can be empty), which will work on elements of an array:

$ a=('a' '' 'b' 'c')
$ echo ${(j/./.)a:#}
a.b.c
$ # If the expansion is in double quotes, add the @ flag:
$ echo "${(@j/./.)a:#}"
a.b.c

man 1 zshexpn:

${name:#pattern} If the pattern matches the value of name, then substitute the empty string; otherwise, just substitute the value of name. If name is an array the matching array elements are removed (use the (M) flag to remove the non-matched elements).

There is the parameter expansion ${name:#pattern} (pattern can be empty), which will work on elements of an array:

$ a=('a' '' 'b' 'c')
$ echo ${(j/./)a:#}
a.b.c
$ # If the expansion is in double quotes, add the @ flag:
$ echo "${(@j/./)a:#}"
a.b.c

man 1 zshexpn:

${name:#pattern} If the pattern matches the value of name, then substitute the empty string; otherwise, just substitute the value of name. If name is an array the matching array elements are removed (use the (M) flag to remove the non-matched elements).

There is the parameter expansion ${name:#pattern} (pattern can be empty), which will work on elements of an array:

a=('a' '' 'b' 'c')
echo ${(j./.)a:#}
# If the expansion is in double quotes, add the @ flag:
echo "${(@j./.)a:#}"

man 1 zshexpn:

${name:#pattern} If the pattern matches the value of name, then substitute the empty string; otherwise, just substitute the value of name. If name is an array the matching array elements are removed (use the (M) flag to remove the non-matched elements).

Source Link
guest
  • 2.2k
  • 6
  • 11

There is the parameter expansion ${name:#pattern} (pattern can be empty), which will work on elements of an array:

$ a=('a' '' 'b' 'c')
$ echo ${(j/./)a:#}
a.b.c
$ # If the expansion is in double quotes, add the @ flag:
$ echo "${(@j/./)a:#}"
a.b.c

man 1 zshexpn:

${name:#pattern} If the pattern matches the value of name, then substitute the empty string; otherwise, just substitute the value of name. If name is an array the matching array elements are removed (use the (M) flag to remove the non-matched elements).