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

Re: counting trouble



On Apr 4,  7:07pm, Ray Andrews wrote:
}
} On 04/04/18 06:15 PM, Bart Schaefer wrote:
} > Please don't think about globbing as returning "lines".  It doesn't.
}
} But:
} 
}     tmp=( ${1}*(N) )
} 
} ... seems to give me exactly that -- an array split on lines

But it's NOT lines, any more than the elements of a C array are lines
(and internally, to zsh at least, it *IS* a C array of nul-terminated
strings -- other shells such as bash use a linked list, etc.).

In the shell grammar sense, it's an array of "shell words".

A directory does not contain "lines", it contains file names.  When you
use a glob, you're extracting the matching file names one by one, not
grepping a text stream of all those names and then splitting it up at
line breaks.

}    print -l "${tmp[@]}\n"
} 
} ... does exactly what I'm expecting

But print is receiving individual "shell words" as its argument list,
one array element per word.  The -l option causes print to *add* the
line breaks.  If you replace -l with -N you don't get line breaks,
you get nul bytes.

(Except given that construction plus print's usual interpretation of
backslash-escapes, you've pasted an extra newline on the final word.)
 
} What would be manna from heaven is to be able to look at an array and 
} 'see' the construction of it -- how it's split, if one could see the 
} newlines and/or spaces in both input and output that would be huge.

There's no perfect way to do that because there's intentionally no
character that you could use to show where the words begin and end
that can't also theoretically appear IN one of the words.  You could
step in with a debugger like gdb and use it to display the internal
memory allocations.

If you know you're writing to an ANSI color terminal and you know the
array doesn't contain color changing sequences, you can try something
like this:

    autoload colors
    colors
    wstart="$bg[black]$fg[green]<<$reset_color"
    wend="$bg[black]$fg[yellow]>>$reset_color"
    printf "${wstart}%s${wend}" "${array[@]}"
    print

Adjust wstart and wend until you have something you think is visible
enough.

} If I could see the hidden structure of both input and output there'd
} be a lot less guessing.

I'm not sure what you consider to be an "input" and what an "output".



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