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

Re: why is eval needed?



On 11/19/2022 11:02 AM, Ray Andrews wrote:

On 2022-11-19 06:43, Roman Perepelitsa wrote:
With the default options this this the same as this:
     tree '-L 2'

Is it clear why it doesn't work?

Actually yes ... but that was only my last effort.  With double quotes the error is:

>  -L 2 [error opening dir]

... and with no quotes it's:

> test:local:5: not valid in this context: -L

... to correct myself, it's really the double quoted offering that I'd expect to work.  I'm pretty sure this is an invisible grouping of arguments but I don't know what to do about it other than 'eval'.  I'm thinking that when tree sees: " -L 2 " it's seeing that not as a switch followed by a number, but as a single syntactic element which it's trying to interpret as a directory name.  Which sorta is semi-understandable since the quotes make " -L 2 " into 'one thing' whereas tree want's it to be 'two things'.  How to drop that variable in there so that tree is happy with it?  Is this perhaps a bit of crabbiness on the part of tree?  Should " -L 2 " be an array?? Sheesh, that might keep tree happy.  And ...

    local level=( -L 2 )
    tree $level

...

Success!  Ha! You give me enough feedback that I can talk myself out of the problem :-)


Another option is

    local level='-L 2'

    tree $=level


Word splitting level gives the results you want












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