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

Re: preserving single quotes



2022-09-27 20:12:22 -0700, Ray Andrews:
> I've done this before but I can't remember the invocation.
> 
>    $ dd="echo howdy"
> 
>    $ ee=$($=dd); echo $ee
>    howdy
> 
>    $ dd="aptitude search '?name(libreoffice-java-common)'"
> 
>    $ ee=$($=dd); echo $ee
> 
>    $ (no output)
> 
> 
> ... I have to be able to run the aptitude command with the single quotes
> intact.  I've tried every little trick that's worked before but I'm just not
> finding the magic.


Use either:

dd() aptitude search '?name(libreoffice-java-common)'
ee=$(dd)

Or:

dd="aptitude search '?name(libreoffice-java-common)'"
ee=$(eval -- $dd)

Or:

dd=( aptitude search '?name(libreoffice-java-common)' )
# or
dd=(
  aptitude
  search
  '?name(libreoffice-java-common)'
)
# just to show that it's several arguments you want to store in
# that array
ee=$( "$dd[@]" )

$=dd just does $IFS-splitting. If $dd is meant to contain shell code,
you should use eval to evaluate it. But to store code, you
generally use functions not variables. The z and Q parameter
expansion flags can do the same tokenisation and quote removal
as the shell syntax parser does, but I don't think you want to
go there.

-- 
Stephane




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