From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 21613 invoked by alias); 8 Mar 2017 15:54:46 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 40796 Received: (qmail 4938 invoked from network); 8 Mar 2017 15:54:46 -0000 X-Qmail-Scanner-Diagnostics: from mailout2.w1.samsung.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.99.2/21882. spamassassin: 3.4.1. Clear:RC:0(210.118.77.12):SA:0(-5.0/5.0):. Processed in 3.2901 secs); 08 Mar 2017 15:54:46 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-5.0 required=5.0 tests=RCVD_IN_DNSWL_HI, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=unavailable autolearn_force=no version=3.4.1 X-Envelope-From: p.stephenson@samsung.com X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: none (ns1.primenet.com.au: domain at samsung.com does not designate permitted sender hosts) X-AuditID: cbfec7f5-f79d06d000004445-61-58c026e09e9e Date: Wed, 08 Mar 2017 15:44:28 +0000 From: Peter Stephenson To: Zsh hackers list Subject: Re: export "a=b"=~ Message-id: <20170308154428.466197e9@pwslap01u.europe.root.pri> In-reply-to: <20170308132345.GA18254@fujitsu.shahaf.local2> 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+NgFnrLIsWRmVeSWpSXmKPExsWy7djPc7oP1A5EGGy9KGxxsPkhkwOjx6qD H5gCGKO4bFJSczLLUov07RK4Ms71r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sNgFDiamb ZjOC2CICWhI7Tp4EqxEWkJa4cWY5WA2vgL3EsRv/2EBsTgFriZnX37FDDN3OKPH3wGEWkAS/ gL7E1b+fmCAOtJeYeeUMI0SzoMSPyffAapiBFmze1sQKYctLbF7zlhnEFhJQl7hxdzf7BEbh WUhaZiFpmYWkZQEj8ypGkdTS4tz03GJDveLE3OLSvHS95PzcTYzAONp27OfmHYyXNgYfYhTg YFTi4RUQPhAhxJpYVlyZe4hRgoNZSYQ3UxkoxJuSWFmVWpQfX1Sak1p8iNEUGDITmaVEk/OB MZ5XEm9oYmhuaWhkbGFhbmSkJM5b8uFKuJBAemJJanZqakFqEUwfEwenVAOj397pkkcE9uk8 PVeV/eapw/+TimXTHjkGBDyV3fjPrzZ+zYEZVRK56uricr7dmydM0pZjqup1XFMoLKhW/3dC UsTyX6Fr3x5ruet3/c3iXcu8or7u89jayrWTv3HGmRfK+5u7vzyfdGL6mZb1Rn+Kel7+SXo0 0f8M8/Jsvb1aSQyGO66msHZYKLEUZyQaajEXFScCADwlPay5AgAA X-MTR: 20000000000000000@CPGS X-CMS-MailID: 20170308154431eucas1p2e3024b0eeb941789709e26dbd2b8a87e X-Msg-Generator: CA X-Sender-IP: 182.198.249.179 X-Local-Sender: =?UTF-8?B?UGV0ZXIgU3RlcGhlbnNvbhtTQ1NDLURhdGEgUGxhbmUb?= =?UTF-8?B?7IK87ISx7KCE7J6QG1ByaW5jaXBhbCBFbmdpbmVlciwgU29mdHdhcmU=?= X-Global-Sender: =?UTF-8?B?UGV0ZXIgU3RlcGhlbnNvbhtTQ1NDLURhdGEgUGxhbmUbU2Ft?= =?UTF-8?B?c3VuZyBFbGVjdHJvbmljcxtQcmluY2lwYWwgRW5naW5lZXIsIFNvZnR3YXJl?= X-Sender-Code: =?UTF-8?B?QzEwG0VIURtDMTBDRDA1Q0QwNTAwNTg=?= CMS-TYPE: 201P X-HopCount: 7 X-CMS-RootMailID: 20170308132910epcas1p33144f6d5af5a6983019959a010930e83 X-RootMTR: 20170308132910epcas1p33144f6d5af5a6983019959a010930e83 References: <20170308085000.GA6975@chaz.gmail.com> <20170308132345.GA18254@fujitsu.shahaf.local2> On Wed, 8 Mar 2017 13:23:45 +0000 Daniel Shahaf wrote: > Stephane Chazelas wrote on Wed, Mar 08, 2017 at 08:50:00 +0000: > > Not that it's likely to ever be a concern, but I just noticed: > > > > $ zsh -c 'export "a"=a=~; echo $a' > > a=~ > > $ zsh -c 'export "a=a"=~; echo $a' > > a=/home/chazelas > > $ zsh -c 'export a=a=~; echo $a' > > a=~ > > > > (5.1.1) > > [ I assume the point is that tilde expansion wasn't expected in the > second case. ] > > Same behaviour in latest master. This is because the MAGIC_EQUAL_SUBST > option, even when unset, implicitly applies to "export". (The > declaration of "export" in builtins.c has the BINF_MAGICEQUALS flag > since before CVS.) > > Should the behaviour be changed in 'emulate sh' / 'setopt posix*' mode? I think that flag is now largely redundant since these days the "~" expansion is normally triggered by parsing the variable and argument separately, in which case the older "magic" behaviour isn't useful. Hence, regardless of compatibility mode, we should probably suppress that flag in this case, leaving the fix-up magic behaviour for when we encounter a builtin without recognising it as a keyword in the parser (an unusual case where it's OK to make reasonable guesses and compatibility with older zsh is probably the right answer). So I think the following ought to work without any significant side effects. I've renamed the controlling variable for clarity; the older, more general, name is now purely historical. One extra thing: it seems likely that you don't want MAGIC_EQUAL_SUBST behaviour *at all* in the case where you recognised the keyword, i.e. even if the option is explicitly set, right? So I've changed that, too. In other words, setopt magicequalsubst typeset "a=a"=~ *still* only assigns the value 'a=~'. See comment I've added for the full logic. It would certainly be possible not to set magic_assign if the POSIX_BUILTINS option is on, too, but that's now a very minor effect. pws diff --git a/Src/exec.c b/Src/exec.c index 8b32246..ec415cf 100644 --- a/Src/exec.c +++ b/Src/exec.c @@ -2658,7 +2658,7 @@ execcmd_exec(Estate state, Execcmd_params eparams, char *text; int save[10]; int fil, dfil, is_cursh, do_exec = 0, redir_err = 0, i; - int nullexec = 0, assign = 0, forked = 0; + int nullexec = 0, magic_assign = 0, forked = 0; int is_shfunc = 0, is_builtin = 0, is_exec = 0, use_defpath = 0; /* Various flags to the command. */ int cflags = 0, orig_cflags = 0, checked = 0, oautocont = -1; @@ -2761,7 +2761,8 @@ execcmd_exec(Estate state, Execcmd_params eparams, /* autoload the builtin if necessary */ if (!(hn = resolvebuiltin(cmdarg, hn))) return; - assign = (hn->flags & BINF_MAGICEQUALS); + if (type != WC_TYPESET) + magic_assign = (hn->flags & BINF_MAGICEQUALS); break; } checked = 0; @@ -2929,8 +2930,22 @@ execcmd_exec(Estate state, Execcmd_params eparams, if (noerrexit == 2 && !is_shfunc) noerrexit = 0; - /* Do prefork substitutions */ - esprefork = (assign || isset(MAGICEQUALSUBST)) ? PREFORK_TYPESET : 0; + /* Do prefork substitutions. + * + * Decide if we need "magic" handling of ~'s etc. in + * assignment-like arguments. + * - If magic_assign is set, we are using a builtin of the + * tyepset family, but did not recognise this as a keyword, + * so need guess-o-matic behaviour. + * - Otherwise, if we did recognise the keyword, we never need + * guess-o-matic behaviour as the argument was properly parsed + * as such. + * - Otherwise, use the behaviour specified by the MAGIC_EQUAL_SUBST + * option. + */ + esprefork = (magic_assign || + (isset(MAGICEQUALSUBST) && type != WC_TYPESET)) ? + PREFORK_TYPESET : 0; if (args && eparams->htok) prefork(args, esprefork, NULL); @@ -3710,7 +3725,7 @@ execcmd_exec(Estate state, Execcmd_params eparams, * Save if it's got "command" in front or it's * not a magic-equals assignment. */ - if ((cflags & (BINF_COMMAND|BINF_ASSIGN)) || !assign) + if ((cflags & (BINF_COMMAND|BINF_ASSIGN)) || !magic_assign) do_save = 1; } if (do_save && varspc)