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

Re: why is eval needed?



On Sat, Nov 19, 2022 at 7:03 PM Clinton Bunch <cdb_zsh@xxxxxxxxxxx> wrote:
>
> Another option is
>
>      local level='-L 2'
>
>      tree $=level

If you really have to use a scalar instead of an array and then split
it, then doing the following is usually the way to go:

    local args=(${(z)level})
    tree "${(@Q)args}"

This allows you to pass quoted and empty arguments:

    level='foo "bar baz" "" qux'

Note that if you combine the two expansions into one
("${(@Q)${(@z)level}}"), you'll have incorrect results when $level is
empty.

You can do the reverse transformation--from array to scalar--like this:

    local array=(...)
    local scalar=${(@q)array}

Roman.




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