From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 1919 invoked by alias); 24 Nov 2015 09:38:09 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 20978 Received: (qmail 5068 invoked from network); 24 Nov 2015 09:38:06 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.0 X-AuditID: cbfec7f5-f79b16d000005389-d2-56542ff9b9fc Date: Tue, 24 Nov 2015 09:37:58 +0000 From: Peter Stephenson To: Zsh Users Subject: Re: Nested quotes Message-id: <20151124093758.2834203f@pwslap01u.europe.root.pri> In-reply-to: <20151124073627.GA14441@linux.vnet.ibm.com> References: <20151124073627.GA14441@linux.vnet.ibm.com> Organization: Samsung Cambridge Solution Centre X-Mailer: Claws Mail 3.7.9 (GTK+ 2.22.0; i386-redhat-linux-gnu) MIME-version: 1.0 Content-type: text/plain; charset=US-ASCII Content-transfer-encoding: 7bit X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrHLMWRmVeSWpSXmKPExsVy+t/xq7o/9UPCDLYvlbfYcXIlowOjx6qD H5gCGKO4bFJSczLLUov07RK4MjZd0CqYxltxeMMGlgbGLVxdjJwcEgImEj/fH2SCsMUkLtxb z9bFyMUhJLCUUWLvjkvsEM40JolJfw+zQDjnGCW2fznECNIiJHCWUWJNpy6IzSKgKvGg8Swr iM0mYCgxddNssBoRAUWJM7++ga0QFpCSmN72mhnE5hWwl7g6ZTbQUA4OTgELiVUNbBAjzSUu 3n0P1sovoC9x9e8nqOvsJWZeOcMI0Soo8WPyPRYQm1lAS2LztiZWCFteYvOat8wQc9Qlbtzd zT6BUXgWkpZZSFpmIWlZwMi8ilE0tTS5oDgpPddIrzgxt7g0L10vOT93EyMklL/uYFx6zOoQ owAHoxIP74eS4DAh1sSy4srcQ4wSHMxKIrzLXwGFeFMSK6tSi/Lji0pzUosPMUpzsCiJ887c 9T5ESCA9sSQ1OzW1ILUIJsvEwSnVwLiJJbv1V+SBr7lOUze+mtKldvvEOsaY4FCW2Ze3eTsJ Xbx2aOb2dSxOWUvePTms+rrwUsCDZ9Nk5ZLTsiRyVz53WqWdcD53Qc80ofWz1nJqiRnfS6m6 zuDnaHIsY8XhRVcDpATCXjTvzv/z7P0Oi49nT0s8Eg/5O+ffzaplye4RM26veTXnMmu0Ektx RqKhFnNRcSIAnAAOWWECAAA= On Tue, 24 Nov 2015 08:36:27 +0100 Dominik Vogt wrote: > Maybe I'm just thick this morning, but how do you "nest" double > quotes here: > > $ FILE="foo bar" > $ echo "$(readlink -f $FILE)" > readlink: extra operand `bar' > > Obviously $FILE needs to be quoted too. I'm guessing the difference between you and Simon is you have the SH_WORD_SPLIT option set for some sort of sh-compatibility. You've now discovered why it's not set by default. You either to turn the option off again or provided explicit quoting of $FILE where it occurs as an argument to readlink. To wokr out how to quote it, you need to know that the fact the readlink command is in $(...) inside quotes can be ignored --- the contents of an $(...) expression are parsed step by step, so the only thing that will terminate it is that closing ")", which can't occur in a syntactically valid fashion for any other reason. (That wasn't fully true until quite recently, but the details only involve odd cases like case statements where unpaired closing parentheses occur, so you can ignore this subtlety for simple expressions even with older versions of the shell.) So it's fine to do echo "$(readlink -f "$FILE")" but you might want to consider unsetopt shwordsplit particularly if other people are using your zsh scripts functions. It's also possible to turn SH_WORD_SPLIT off for one substitution, echo "$(readline -f ${==FILE}" but that's got no obvious advantage here over simply quoting it, and it's not portable. The only advantage I can see is it's explicit to a seasoned zsh user what you're trying to do. pws