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

Re: psychiatric help



> BTW, polite of 'ls' to make multiline output when input is an array..

 First, ls doesn't know from shell arrays. It takes a list of arguments. They show up inside the program as an array at the C level, but that's different. 

Once you get past any options (indicated by -), it interprets the arguments as filenames. With no options it just behaves as a glorified echo and spits those names back out to you - although unlike echo it will complain if any of them don't exist as files.

If its output is not going to a terminal, you get the "polite" behavior that outputs one filename per line. Any time you're doing `ls |` or `$(ls)` or `<(ls)`, the output is not going to a terminal, so you get the one-per-line behavior. 

I still don't know why you need a string and eval instead of just using `$out` directly.

--
Mark J. Reed <markjreed@xxxxxxxxx>


On Sun, Apr 5, 2026 at 13:28 Ray Andrews <rayandrews@xxxxxxxxxxx> wrote:


On 2026-04-04 20:57, Bart Schaefer wrote:

If you need to copy $@ (et al.) into another variable, use array syntax:
out=( $@ )
Tried this:

alias tt='noglob _tt'
function _tt ()
{
out=( $@ )                # Bart sez.  Array will preserve hard space, no backslash needed.
_execute 'ls $~out'    # Need tilde here!

foo='ls $~out'            # Literal string! Don't forget tilde, same as above.  Consistent.
_execute $foo            #  Plain vanilla var sends literal string, and 'eval' takes care of it.
}

run:

4 /aWorking/Zsh/Source/Wk 4 % test\ ?

test a
test b

test a
test b

... so that's got it under control.  '_execute' boils down to a call to 'eval' as you suspect but it does a bunch of other stuff as well.  Easy to drop the ball tho, the chain of handoffs can be fuddled at any point.  Gotta get it right, I was making it harder than it is. 80% clarity.

Thank you Sensei.

BTW, polite of 'ls' to make multiline output when input is an array.






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