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

Re: string to array space problem in filenames



2015-09-03 08:58:04 -0700, Ray Andrews:
> On 09/03/2015 08:30 AM, Mikael Magnusson wrote:
> 
> >-r is good to use as I explained in my other mail, -u2 means to
> >print to stderr which would be a very strange thing to do here,
> >since it won't go to 'file'.
> 
> I was just typing a post to ask about that ... I'll take that on
> faith, however one further question:
> 
> 	print -rl - "${array[@]}" > file
> 
> ... do I or don't I like the double dash that seems to usually be there?
> And a few code specimens have shown no dash(es) at all there, which scares
> me since disaster is never far away from the unwary.

An annoying thing with print -l (and it's the same with its
standard equivalent printf '%s\n') is that you get the same
output for an empty list and a list of one empty element.

That is:

list=()
print -rl -- "$list[@]"

list=('')
print -rl -- "$list[@]"

both print one empty line.

so, strictly speaking, you need to write it:

println() {
  [ "$#" -eq 0 ] ||
    printf '%s\n' "$@"
}

println "$list[@]"

-- 
Stephane



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