zsh-users
 help / color / mirror / code / Atom feed
From: Ray Andrews <rayandrews@eastlink.ca>
To: zsh-users@zsh.org
Subject: Re: protect spaces and/or globs
Date: Wed, 10 Feb 2021 07:18:49 -0800	[thread overview]
Message-ID: <cbcc17c7-e4c6-638d-8d6f-931fa5fe5097@eastlink.ca> (raw)
In-Reply-To: <87a6sc3d0c.fsf@lwm.klanderman.net>

On 2021-02-09 5:52 p.m., Greg Klanderman wrote:

     It works Greg, but it misses the crux of my problem which is that 
all my wrappers run everything thru 'eval'
as below (simplified from your original):

grep_wrapper ()
{
   grepargs=()
   sstring=
   while [[ $# -gt 0 ]] ; do
     arg="$1"
     shift
       grepargs+=( "$arg" )                            # This is what 
Peter was saying.
   done
#  grep --color=always -i -- "${grepargs[@]}"         # Works fine but ...
   sstring="grep --color=always -i -- ${grepargs[@]}"  # I need to save 
to a scalar ...
   print -rS "$sstring"                                # Write to 
history ...
   eval "$sstring"                                     # And 'eval'.

   print -r "\n$sstring"
}

9 /aWorking/Zsh/Source/Wk 4 $ . test; grep_wrapper 'on the current' 
'i,2,light edit' 'i,1,old stable'
grep: the: No such file or directory
grep: current: No such file or directory
grep: i,2,light: No such file or directory
grep: edit: No such file or directory
grep: i,1,old: No such file or directory
grep: stable: No such file or directory

grep --color=always -i -- on the current i,2,light edit i,1,old stable

     ... as before the quotes are stripped if I do it my way.  But as I 
discovered last night:

9 /aWorking/Zsh/Source/Wk 4 $ . test; grep_wrapper "'on the current' 
'i,2,light edit' 'i,1,old stable'"
i,2,light edit:Find any command named 'mtr*' on the current path.
i,1,old stable:Find any command named 'mtr*' on the current path.

grep --color=always -i -- 'on the current' 'i,2,light edit' 'i,1,old stable'

     ... by simply double quoting the argument string, the single quotes 
are preserved and 'eval' works.

She is NOT being unreasonable.   Just do it her way and everything will 
be fine.
A lesson for life.



  parent reply	other threads:[~2021-02-10 15:19 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-09 20:42 Ray Andrews
2021-02-09 21:05 ` Lawrence Velázquez
2021-02-09 21:08 ` Peter Stephenson
2021-02-09 23:45   ` Ray Andrews
2021-02-10  0:22     ` Lawrence Velázquez
2021-02-10  0:51       ` Ray Andrews
2021-02-10  1:46         ` Lawrence Velázquez
2021-02-10  2:25           ` Ray Andrews
2021-02-10  2:52             ` Lawrence Velázquez
2021-02-10  1:52         ` Greg Klanderman
2021-02-10  2:29           ` Ray Andrews
2021-02-10 15:18           ` Ray Andrews [this message]
2021-02-10 15:47             ` Peter Stephenson
2021-02-10 16:19               ` Ray Andrews
2021-02-10 16:29                 ` Peter Stephenson
2021-02-10 20:53                   ` Ray Andrews
2021-02-10 22:14                     ` Bart Schaefer
2021-02-11 16:31                       ` Ray Andrews
2021-02-11 17:19                         ` Lawrence Velázquez
2021-02-11 19:48                           ` Ray Andrews
2021-02-10 18:08                 ` Bart Schaefer
2021-02-10 20:56                   ` Ray Andrews
2021-02-10 16:28             ` Lawrence Velázquez

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=cbcc17c7-e4c6-638d-8d6f-931fa5fe5097@eastlink.ca \
    --to=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).