Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: preserving single quotes
- X-seq: zsh-users 28158
- From: Stephane Chazelas <stephane@xxxxxxxxxxxx>
- To: Ray Andrews <rayandrews@xxxxxxxxxxx>
- Cc: Zsh Users <zsh-users@xxxxxxx>
- Subject: Re: preserving single quotes
- Date: Wed, 28 Sep 2022 11:00:20 +0100
- Archived-at: <https://zsh.org/users/28158>
- In-reply-to: <b1f88f62-0dba-92df-d09d-9025c6846551@eastlink.ca>
- List-id: <zsh-users.zsh.org>
- Mail-followup-to: Ray Andrews <rayandrews@xxxxxxxxxxx>, Zsh Users <zsh-users@xxxxxxx>
- References: <b1f88f62-0dba-92df-d09d-9025c6846551@eastlink.ca>
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