Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: vanishing spaces
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
Messages sorted by:
Reverse Date,
Date,
Thread,
Author