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

Re: why is eval needed?

On 2022-11-20 12:16, Stephane Chazelas wrote:

But that's the thing, I'd naively thought the variable could be inserted in
the command string and be 'just' a string of characters, but zsh imposes
that 'tree' must see '-L 2' as a single entity, yes?
No, you have it completely backwards.
But everything so far seems to tell me that I'm right.  When '-L 2' is presented as two arguments instead of one, everything is fine. Are we miscommunicating?
And I think at the heart
of your misunderstanding there is the misconception that you
pass a "command string" to an executable.

You do not, you pass a list of arguments.

I know, but at least on the command line one can think of it as a string.  I understand that it it will be parsed as 'words' (including spaces if quoted).

Why store those two arguments as a string with a space in between them
and then ask the shell to split it, that makes no sense.
I know that now.  But as we discussed, the normal thing is for a switch to present as a single argument so that's what I did.  I quite understand the mistake NOW.
(¹ a complication and a spanner in the works is that environment
variables (those VAR=value strings passed in envp[] above) are
string/scalar only; in csh and in the Bourne shell, shell variables and
env variables were more separated than they are in modern shells).
Awesome that you can keep all this stuff in memory and not get your wires crossed.

What about:

   'my file.txt'
   'my other file.txt'
rm -- $files

Should they be split too?
No, I understand that well.  I think this is a closed issue, I think I'm quite content.
Ah!  So my little issue is a zsh exclusive?
No, again, any recent shell
Ok, not 'exclusive' but it's been a point of difference between at least zsh and bash.
No, it's not tree being difficult. In any command doing

Bbbbut we've agreed that tree is being difficult!  You've explained it in great detail.

apt-file is your friend.
So it is!
Will tell you what package the tree command comes from.

apt showsrc that-package

It's just not something I need to worry about.  To me it's all 'Linux'.  Maybe one day I'll download some sources (if in C) and start tinkering.  For now it just doesn't matter.   The thing is to get a bit more competent with zsh.

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