zsh-users
 help / color / mirror / code / Atom feed
From: Marc Chantreux <mc@unistra.fr>
To: Ray Andrews <rayandrews@eastlink.ca>
Cc: Zsh Users <zsh-users@zsh.org>
Subject: Re: vanishing spaces
Date: Sat, 30 Mar 2024 17:07:09 +0100	[thread overview]
Message-ID: <Zgg4rXc5osTViiJG@prometheus> (raw)
In-Reply-To: <3643c571-5830-420c-9d1f-88a6bf22cc0e@eastlink.ca>

On Sat, Mar 30, 2024 at 08:18:30AM -0700, Ray Andrews wrote:

> % aptitude search '~i?name(nvidia)'

aptitude search '~i~nnvidia' for short. check it out:

	aptitude-doc-en: /usr/share/doc/aptitude/html/en/ch02s04s05.html

>     ... I have reason to capture the output of several versions of aptitude
> searches into a variable. I hope 'eval' is the right way:

about the vanishing spaces: it's because you need to protect them with
quotes both while reading and writing them:

bad:

	output=$( eval $* )
	echo $output

good:

	output="$( eval $* )"
	echo "$output"

Aside: I don't understand why you eval it. it's ok to write

	output="$( aptitude search '~i~nnvidia' )"

plus: I try to avoid eval as much as possible because it's fragile.
if your command is stored in "$@" with all the parameters set correctly,
you don't need eval:

	set -- aptitude search '~i~nnvidia'
	output=$( "$@" )

quotes are important here also as "$@" will be expanded as

	"aptitude" "search" "~i~nnvidia"

HTH,
marc


  parent reply	other threads:[~2024-03-30 16:07 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-30 15:18 Ray Andrews
2024-03-30 16:07 ` Bart Schaefer
2024-03-30 16:07 ` Marc Chantreux [this message]
2024-03-30 17:16   ` Ray Andrews

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Zgg4rXc5osTViiJG@prometheus \
    --to=mc@unistra.fr \
    --cc=rayandrews@eastlink.ca \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).