From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, MAILING_LIST_MULTI,NICE_REPLY_A,RCVD_IN_DNSWL_MED,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 24465 invoked from network); 11 Feb 2021 16:32:05 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 11 Feb 2021 16:32:05 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20200801; t=1613061125; b=rr35zY5q0Sq6iEzi/0BYRZl5Tn6gx5KvnGwwA2evnSH6jy3Bq+J9dkt8ADGFlyLVJ2y7Cnf3pa HwQexVjcvo5pdDrdhdsXE8p8ZzDx2BXu4W9sd7+P/wyDLWg8XYeJbaFUkZC6AD3NyIPVLRqz6W FyhllLVDBSk2LvkdwB/cXS+ieARFMKXfSO0XX6cK30Uf2X1yC9ivbYQXt6edjwr5HKHHLM1M0U 8TDMFB+t95uso4DJy0KMU0HjgAMxe0HTQ3NzeBIQMdkQtee9RKcmiVC1KlxlfmQ2X8x13n7D7F XiA7wZi1mKgwjB4KpE4wzCtECr3OJZKc4yJK2kUnTGk3Bg==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mta02.eastlink.ca) smtp.remote-ip=24.224.136.13; dmarc=none header.from=eastlink.ca; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20200801; t=1613061125; bh=HFS+DC0JhwbUdLPw3QOJtLrGQjMCSsbhHTuteXbdPJM=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Transfer-Encoding:Content-Type:In-Reply-To: MIME-Version:Date:Message-ID:From:References:To:Subject:DKIM-Signature; b=tbkWt+3Ygvg3dftLgcPd8TVPjCKD9j6hS4gnIvHC5fJMKMdigIb1CgKdXrtAuOH77k8keOqhp0 NEzzctBENLGLJ0e9+wtC4h4InhtTVncwnuMo4UAOL8RMg0BcUpE8wxNNcPTHloOlN46u5bckkz WAIBVwWvIjdXVG7dwl9QgDJNhw3kam+LKV2ANCW+GenwBtP1Zb5TYRVv/F+wknggTMFNcwCZ7R r0Ld7xJmqtddY3oXu5296NFMCxqriqxVOVVsRyiZUAanA0RyA6Tv9e1KlnF32ptBVPCwxdyrU0 U2mxyyO7AOV5J4w+HIrEQkKWLbsV/df0y4T29cdRk6YV8w==; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20200801; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:Content-transfer-encoding: Content-type:In-reply-to:MIME-version:Date:Message-id:From:References:To: Subject:Reply-To:Cc:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=aATmKq5KhuHBMhGW+85jm9hhBaCud2Ur3mCH/FQXbU4=; b=fUZOBLPQOxrBLhJJ8ekJgVzXMi 5zgIaigD6SOsR1/qoP/zCWMI2ApO9RISLSFBh76AlLguhmoVl3d5b2ryd5XAEWpPoVvRK6yGgaT2F uL1NsgUyUyWs3DE76H6fStPXvlhfxBltVElA+FI1L3I4yJbI0GSyXHaX/UTnY7sBmn4mgiFxhJyBe wQRT7+WHFvx71/m+LMg0xokHg/5Fj/H7T1J/ExN0VhZXERNR0geLI/dZWlQ8/AXa3DqZDkPWYmu12 ZmnP6wUEaf+xk4Csw523PgTAz7rCQ68GsgyXJNMnXmUG73ktvrkKju118WpQwvmakmeWzGcqz//FS HR8yoCHw==; Received: from authenticated user by zero.zsh.org with local id 1lAEsr-0004qv-Vr; Thu, 11 Feb 2021 16:32:02 +0000 Authentication-Results: zsh.org; iprev=pass (mta02.eastlink.ca) smtp.remote-ip=24.224.136.13; dmarc=none header.from=eastlink.ca; arc=none Received: from mta02.eastlink.ca ([24.224.136.13]:38341) by zero.zsh.org with esmtps (TLS1.2:ECDHE-RSA-AES128-GCM-SHA256:128) id 1lAEsH-0004U6-O6; Thu, 11 Feb 2021 16:31:27 +0000 Received: from csp01.eastlink.ca ([71.7.199.166]) by mta02.eastlink.ca (Oracle Communications Messaging Server 8.0.2.2.20180531 64bit (built May 31 2018)) with ESMTPS id <0QOD005H0GCLIZ91@mta02.eastlink.ca> for zsh-users@zsh.org; Thu, 11 Feb 2021 12:31:23 -0400 (AST) Received: from [192.168.0.3] ([24.207.90.194]) by Eastlink with ESMTP id AEsFls8W1sAqKAEsFldkT1; Thu, 11 Feb 2021 12:31:23 -0400 X-Authority-Analysis: v=2.4 cv=W6f96Tak c=1 sm=1 tr=0 ts=60255bdb a=zv49KfEsxEDzuN5AGO7r0Q==:117 a=zv49KfEsxEDzuN5AGO7r0Q==:17 a=IkcTkHD0fZMA:10 a=hD_jbGtJvqqu6kr5NYIA:9 a=QEXdDO2ut3YA:10 X-Vade-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrheelgdekkecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfgtefuvffnkffpmfdpqfgfvfenuceurghilhhouhhtmecufedttdenucenucfjughrpefuvfhfhffkffgfgggjtgfgsehtkeertddtfeejnecuhfhrohhmpeftrgihucetnhgurhgvfihsuceorhgrhigrnhgurhgvfihssegvrghsthhlihhnkhdrtggrqeenucggtffrrghtthgvrhhnpeekvdeuuefffefhvdeuieetffdvtddvjeegueejkeeiudehieetieehgeetvdfhfeenucfkphepvdegrddvtdejrdeltddrudelgeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpedvgedrvddtjedrledtrdduleegpdhhvghloheplgduledvrdduieekrddtrdefngdpmhgrihhlfhhrohhmpehrrgihrghnughrvgifshesvggrshhtlhhinhhkrdgtrgdprhgtphhtthhopeiishhhqdhushgvrhhsseiishhhrdhorhhgpdhgvghtqdgkihhprfgrshhsfigupehtrhhuvg X-Vade-Score: 0 X-Vade-State: 0 X-EL-IP-NOAUTH: 24.207.90.194 Subject: Re: protect spaces and/or globs To: zsh-users@zsh.org References: <52D5DA56-397F-40BB-BBA7-CE3BF7256581@larryv.me> <29a203d5-bf53-9cb7-7a49-2705c3b1d8f2@eastlink.ca> <87a6sc3d0c.fsf@lwm.klanderman.net> <752329601.3729797.1612972051119@mail2.virginmedia.com> <379883051.3731455.1612974540761@mail2.virginmedia.com> From: Ray Andrews Message-id: <8a718224-f0e4-d960-1d65-f600ec818415@eastlink.ca> Date: Thu, 11 Feb 2021 08:31:22 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.7.0 MIME-version: 1.0 In-reply-to: Content-type: text/plain; charset=utf-8; format=flowed Content-transfer-encoding: 8bit Content-language: en-US X-Seq: 26505 Archived-At: X-Loop: zsh-users@zsh.org Errors-To: zsh-users-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-users-request@zsh.org X-no-archive: yes List-Id: List-Help: List-Subscribe: List-Unsubscribe: List-Post: List-Owner: List-Archive: Archived-At: On 2021-02-10 2:14 p.m., Bart Schaefer wrote: > > You probably want (@q-) there, to minimize the number of quoted > things, or (@q+) if you use a lot of unicode characters or control > strings. Seems to be working fine: grep_wrapper () {   grepargs=()   sstring=   while [[ $# -gt 0 ]] ; do     arg="$1"     shift       grepargs+=( "$arg" )   done   sarray=(grep --color=always -i -- "${grepargs[@]}")   print -sr -- "${(@q)sarray}"   echo "\nwhat should be going to history:"   print -r -- "${(@q)sarray}"   echo "\neval:"   eval "${(@q)sarray}" }     Test run: 9 /aWorking/Zsh/Source/Wk 3 $ . test; grep_wrapper 'on the current' 'i,2,light edit' 'i,1,old stable' what should be going to history: grep --color=always -i -- on\ the\ current i,2,light\ edit i,1,old\ stable eval: 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.     Up arrow to recall and then re-execute: 9 /aWorking/Zsh/Source/Wk 3 $ grep --color=always -i -- 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. -------------------------------------------------------------------------------------------------------------------- So, the single quotes might be protected by double quoting as I had it before, or we can use the magic of ' (q) ' to protect the spaces with backslashes even though the single quotes themselves are gone.  Or, using ' (q-) ': 9 /aWorking/Zsh/Source/Wk 3 $ . test; grep_wrapper 'on the current' 'i,2,light edit' 'i,1,old stable' what should be going to history: grep --color=always -i -- 'on the current' 'i,2,light edit' 'i,1,old stable' eval: 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.     Up arrow and re-execute: 9 /aWorking/Zsh/Source/Wk 3 $ grep --color=always -i -- '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. ------------------------------------------------------------------------------------------------------- Seems cleaner, the single quotes are themselves protected or replaced so that it not only runs right, it looks right; on recall it is  visually exactly the same.  And is it not intuitive that, since single quotes already protect their string, if you add protection for the single quotes themselves, you then have a perfectly protected string?  It can be passed from one function to the next unchanged.  This is the holy grail for me. Any gotchas?  Or is that robust?  Can I use it everywhere?  Seems right.  The array separates the arguments even if the might look like they run together in a string. Thanks all.