Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Is it possible to clear empty :-tied elements?



On 2022-07-19 at 21:54 +0200, Sebastian Gniazdowski wrote:
> export -UT CMAKE_PREFIX_PATH="$ZPFX:$CMAKE_PREFIX_PATH" cmake_prefix_path
> 
> The problem is that the variable/array will contain empty element if the
> variable is empty when export is run.
> 
> I wonder if is it possible to somehow clear such empty entry (i.e.: to
> remove :: from "a::b") without another line of code?

Assign it as an array and do _not_ quote the $ZPFX, so that empty values
are not preserved.

  export -UT CMAKE_PREFIX_PATH cmake_prefix_path=($ZPFX "${(s,:,)CMAKE_PREFIX_PATH}")

If you have to be resilient to SH_WORD_SPLIT being enabled, then replace
$ZPFX with ${==ZPFX} instead.

-Phil




Messages sorted by: Reverse Date, Date, Thread, Author