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.3 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 8394 invoked from network); 10 Feb 2021 01:53:04 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 10 Feb 2021 01:53:04 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20200801; t=1612921984; b=m7Yho58GqmUSG2/BaeHKiruKbgqUjf/5cJMWq6Hz4Z+vpBHcPNXtMzrF0KiTlqWqSk/uiqPMJO OwFvk3FICymyKySx6VPhuR8ff19M5xTSI+DsuhbXSaQbrxkA/etBPYsRFH3sO1X0uCpAickQ4P WPFe8kUxUhmI53RYNEjvsrZzazNMmn5zzqrgrySQR8SltLuPQBjOzXPpBJfzhgxqhlRWoUEN36 dM6sv49IABQ4fFfAU17yPcsdosvDoXNCe1fRcNFCv1WjmMMhXrNc5vYx4Rgfa3eBxybQjqaX0k GG2zh3D+nFqU2pEuX7EuC415cCBQeVX1DxsO6lp02st1Kg==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (so254-31.mailgun.net) smtp.remote-ip=198.61.254.31; dkim=pass header.d=klanderman.net header.s=mg header.a=rsa-sha256; dmarc=none header.from=klanderman.net; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20200801; t=1612921984; bh=y5KrHtGYv6OrO9FoAfJsrIR0iw+oN/uAFI0xVuR0jww=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Type:MIME-Version:Message-ID:In-Reply-To:Date: References:Reply-To:Subject:To:From:DKIM-Signature:DKIM-Signature; b=dejSpESjfYo904Aj2KngigE1jyJzyWlXy3OeeqAAjb8NhpbjlI0/PQRmbUB7yd6gEF+ort23Gd 1ny+qI1qnt/1vkMgWRrM96Ej6CXLwz+EPSjeQ5MGAw/zjK2Uo0QsjUaoFSUSMcqCcwpA+DwSEU R+QHLb2weeUMdnKG6vmnmWfr4E8JS4VDF0md+2a4uszMe/XEc94r0s3nnUrjC4aohca64meYb3 TjwLku+1xENb6FOBFZaEx+Q9YlwlOAJrSG5tiIhnF7e5Z7L7iftTPQNHu5+ygQ+ZKhTSQaCt95 QIG/BxtHohsJnSIJlbKajNTOZ++ZrkbN1POfzHnewwt+aA==; 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-Type:MIME-Version:Message-ID: In-Reply-To:Date:References:Reply-To:Subject:To:From:Cc: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=CEVGEDwFPmQYaySj3cVGHTyEcib2jFOFaH9VvJnGo4s=; b=vUQ8Bp7PXhUT+9CrabDbwhli9V j/VAQzyjELgzEesoQRhQweQA0Y7N6Yi29G7notcp9zPQvfc4UiwZfar1LZfXCw2bLaWhLTrCBAp8D kn0n2Tp6rVos/UtXzVP0IPckvDG3EUxOvGb5s7g5ZKe5cK3pat8V/JLujeYsVPNLeJSdY0h/MQN2O kCRhnekcZtZCLUxP/+eSxPGlNerA4hRWl0+DE5U86s4mHweoeTdBajFDCzDTBdMAngGI/K4XAG0gJ 4rI2sDnKIu9YWEpcC4j5KB//dDDw+ctq5M+iXbrmXTCBD9agPFBEZVdX6vmGfJLl7gMGdTPZnNNGJ XUwcYecw==; Received: from authenticated user by zero.zsh.org with local id 1l9egi-0007Ww-A2; Wed, 10 Feb 2021 01:53:04 +0000 Authentication-Results: zsh.org; iprev=pass (so254-31.mailgun.net) smtp.remote-ip=198.61.254.31; dkim=pass header.d=klanderman.net header.s=mg header.a=rsa-sha256; dmarc=none header.from=klanderman.net; arc=none Received: from so254-31.mailgun.net ([198.61.254.31]:64534) by zero.zsh.org with utf8esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1l9egJ-00079p-5P; Wed, 10 Feb 2021 01:52:40 +0000 DKIM-Signature: a=rsa-sha256; v=1; c=relaxed/relaxed; d=klanderman.net; q=dns/txt; s=mg; t=1612921959; h=Content-Type: MIME-Version: Message-ID: In-Reply-To: Date: References: Reply-To: Subject: To: From: Sender; bh=CEVGEDwFPmQYaySj3cVGHTyEcib2jFOFaH9VvJnGo4s=; b=GgIe20O3/BJoeLtUbh++1MFUZ8kOD8Gf+Qc5CCOit8QoyVbhLPHXFFENtoxxlW/LrIBotQ+B QLrTIe6EvcQrYx5qkZBPcAyuQKYTRCBoY52X0CUzWfrpykjUtEHfdAAABAhFFrNK+hWrCfwE +b/b8sYfHsisoNqvl1stMnawVgw= X-Mailgun-Sending-Ip: 198.61.254.31 X-Mailgun-Sid: WyIzOGFmNSIsICJ6c2gtdXNlcnNAenNoLm9yZyIsICI5N2RiZDgiXQ== Received: from smtp2.klanderman.net (smtp2.klanderman.net [142.93.10.110]) by smtp-out-n04.prod.us-east-1.postgun.com with SMTP id 60233c643919dfb4556ba911 (version=TLS1.3, cipher=TLS_AES_128_GCM_SHA256); Wed, 10 Feb 2021 01:52:36 GMT Received: from lwm.klanderman.net (pool-72-93-77-73.bstnma.fios.verizon.net [72.93.77.73]) by smtp2.klanderman.net (Postfix) with ESMTPSA id 3D329414E1; Tue, 9 Feb 2021 20:52:36 -0500 (EST) Received: by lwm.klanderman.net (Postfix, from userid 1000) id E2CD929E1A00; Tue, 9 Feb 2021 20:52:35 -0500 (EST) From: Greg Klanderman To: zsh-users@zsh.org Subject: Re: protect spaces and/or globs Reply-To: Greg Klanderman References: <52D5DA56-397F-40BB-BBA7-CE3BF7256581@larryv.me> <29a203d5-bf53-9cb7-7a49-2705c3b1d8f2@eastlink.ca> Date: Tue, 09 Feb 2021 20:52:35 -0500 In-Reply-To: <29a203d5-bf53-9cb7-7a49-2705c3b1d8f2@eastlink.ca> (Ray Andrews's message of "Tue, 9 Feb 2021 16:51:10 -0800") Message-ID: <87a6sc3d0c.fsf@lwm.klanderman.net> User-Agent: Gnus/5.1008 (Gnus v5.10.8) XEmacs/21.4.24 (linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Seq: 26484 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 February 9, 2021 Ray Andrews wrote: > When a function argument will end up making > an argument to grep, and the argument to grep must have single quotes, but the > single > quotes typed in the function argument are stripped off. What's the solution? You've gone wrong thinking 'the argument to grep must have single quotes'. You need single quotes to get the filename into the function/script as a single argument initially, but if you keep it in an array value, you can then expand the array in the grep invocation preserving the arguments using the "${array[@]}" syntax. consider grep_wrapper () { grepargs=() while [[ $# -gt 0 ]] ; do arg="$1" shift case $arg in --foo* ) echo "do something else with $arg" ;; * ) grepargs+=( "$arg" ) ;; esac done grep --color=always -i -- "${grepargs[@]}" } based on 'unsetopt shwordsplit' and some other options, you can get away without some of the double quoting and {}. but if you want to be able to preserve the empty string, "", as an argument you are pretty much stuck needing double quotes. Greg