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

Re: Parameter expansion flags question



On May 12, 12:02pm, John Cooper wrote:
} Subject: RE: Parameter expansion flags question
}
}   > Placement of the quotes is important:
}   >    for site in ${(f)"$($SITEMGR -i)":#}
} 
} OK, changing the placement of the quotes to the above fixes it. There's
} just one thing I'm a little puzzled about - in the case where $SITEMGR
} produces no output, won't "$($SITEMGR -i)" be the empty string? If so,
} why is :# needed? It seems it will just replace an empty string with
} another empty string?

It's the same as the difference between

string=""
array=( word "$string" word )
print $#array

and

string=""
array=( word $string word )
print $#array

An unquoted empty string is discarded; a quoted empty string is retained.
Effectively the :# construct discards the quoted empty string, leaving an
unquoted one in its place, which the shell in turn discards when building
the final array.



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