From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 21848 invoked by alias); 14 Nov 2017 23:52:59 -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: List-Unsubscribe: X-Seq: 42024 Received: (qmail 4559 invoked by uid 1010); 14 Nov 2017 23:52:59 -0000 X-Qmail-Scanner-Diagnostics: from out4-smtp.messagingengine.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(66.111.4.28):SA:0(-2.6/5.0):. Processed in 2.681784 secs); 14 Nov 2017 23:52:59 -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=-2.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,T_DKIM_INVALID autolearn=ham autolearn_force=no version=3.4.1 X-Envelope-From: d.s@daniel.shahaf.name X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= daniel.shahaf.name; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; bh=XRVoMB oTKENGJs1t978Xomk4uajmhG0BXRM1ZWbVC0k=; b=XhbkDqGT22YXtEfx2EdMpt 9Sb+9VWZv6NF6HVat6EBwss3KxPKVoI07yhdBxLb2mwPOUYk1zjhBziEPLJQOVkN gefY9j7OtsaDnVQwh4WKXRropl42V47FYSnw0m/35CzgJh42AXuGWpuskAuthLY7 e1h5+RNxMOc5IjCc+0kFrmwfAqbR0ZkCE6MO3RVp7hdKtseQuUsE2/Cbnz+i0BYR ynE2mGAWqUBUDqS4hzZh+YqGULOsrjfpJRXo4x8a0beOck2N24znDIo0bX1v32yh tyev6sHBimX9fOMDlPrs2RMAazfrKm4yXR96vD2HKupKC4+Od/6i8bAsAF8ZoIFg == DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; bh=XRVoMB oTKENGJs1t978Xomk4uajmhG0BXRM1ZWbVC0k=; b=Dw+7hVNyacexq0UPvsGe51 HlJuA3RzpBIC2M89hEcL7N7F/tFR9UsPbWQ+Thn4Bg4H7D2e7mr0t8TiI04FdFz8 p37kGvV5M5UlF1/gfU+4uEMBhJrVTjUmTV3vCW/ygoRrC3rO6gv8nI3yWEL5dTgr K6sN0NHjMAH8MmCor6IHy+JNHiJxShu+oMLb+Rz5uBGGMnlh5YvVlSRzZJX/7cVI PsJyoVeMmDH/SuufOM19LVnRmgoCrUBM2W6ECN4Y3LEaPqeKjO+ZT5uIXVrn7m+A SIGOBTAdp2Ya3hzNCmpeNl1uGA08+OQDJkKrKxTBE+/PLWp1IQdxLvH0CopLsCVA == X-ME-Sender: Date: Tue, 14 Nov 2017 23:52:49 +0000 From: Daniel Shahaf To: Martijn Dekker Cc: Zsh hackers list Subject: Re: [PATCH] don't exit shell on [[ -o invalid@option ]] Message-ID: <20171114235249.egcynklamldfcogv@tarpaulin.shahaf.local2> References: <0d6faa9a-fb69-8343-9630-a60d8f1bee0a@inlv.org> <171110143717.ZM16244@torch.brasslantern.com> <20171111124528.035a70ac@ntlworld.com> <38275e86-81c7-dbf8-544e-b0a399a4461d@inlv.org> <171111151905.ZM20139@torch.brasslantern.com> <20171112195657.74fb0b8a@ntlworld.com> <20171114122619.kqa4i2sth66mafrs@tarpaulin.shahaf.local2> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: NeoMutt/20170113 (1.7.2) Martijn Dekker wrote on Tue, Nov 14, 2017 at 15:22:35 +0200: > Op 14-11-17 om 14:26 schreef Daniel Shahaf: > > As Bart hinted, the proposed change is backwards *incompatible*: it > > makes [[ -o invalid@option ]] return 1 where currently it returns 2. > > Actually, it exits/aborts the shell with status 2. This is an essential > difference from simply returning status 2. > Good point, I'd overlooked that. > > Moreover, if cross-version compatibility is the goal, why is it a good > > thing to lump "This shell does not have INVALID_OPTION" and "This shell > > has INVALID_OPTION and it's unset"? > > Because > (a) that's how all other [[ -o ... ]] implementations work, > (b) that's what the current documentation in zshmisc.1 says that [[ -o > ...] does, and > (c) the canonical way to check if an option exists > if (set +o someoption) 2>/dev/null; then ... > works fine on all shells. > > Re (b), zshmisc.1 simply says that [[ -o ... ]] checks if the option is > on. It says nothing about checking if the option exists, much less > aborting the shell if it doesn't. (a) That's a fair point, but I'm not convinced it swings the balance. (I agree that being compatible with bash/ksh is a plus.) (b) zshmisc.1 says "true if the named option var(option) is on". It does not say that it's valid for var(option) not to be an option name at all. Therefore, «[[ -o not_an_option ]]» is undefined behaviour; the documentation does NOT promise that it would behave identically to [[ -o an_unset_option ]]. In other words, the current behaviour is consistent with the documentation. (c) I don't follow your argument. Okay, so «(set +o option)» works, what does that have to do with the behaviour of [[ -o not_an_option ]]? > > It's easy to imagine a situation in > > which that'd be a bug: if INVALID_OPTION was added in zsh version N, is > > set by default, and a plugin that was developed against version N is > > installed by a user running version N-1. > > I don't see how that would introduce a bug. If a new option NEW_OPTION > is introduced in zsh version N, default on, then [[ -o NEW_OPTION ]] can > be used to run code dependent on that new option only if that new option > is on. That code will then never be run on version N-1, which is what is > expected. > You're considering the "if" branch, I'm considering the "else" branch: if [[ -o NEW_OPTION ]]; then lorem; else ipsum; fi "lorem" will only run on zsh vN when the option is set, but "ipsum" will run under vN with the option explicitly unset by the user AND under vN-1. Since the option is on by default, vN-1 should take the "then" branch. > > With the current code that > > situation would result in a (proper) warning. > > A mere warning would be fine, but what actually happens is that the > shell aborts with an error message. > Okay, so how about if we demoted the fatal error to a warning? Like this: % [[ -o not_an_option ]] || echo This gets run zsh: [[: no such option: not_an_option This gets run % > > Devil's advocate, but why can't people just do, today, > > > > if [[ -o INVALID_OPTION ]] 2>/dev/null; then > > Because, on zsh (unlike bash and *ksh) that will cause the shell to > exit, as in, the program aborts. Not only that, adding 2>/dev/null will > cause the program to abort silently, because the error message is > suppressed. > If the fatal error were a warning, the 2> redirection would hide [['s warning but the program would continue. > You can of course do > > if ([[ -o INVALID_OPTION ]]) 2>/dev/null; then > > but that comes at the cost of forking a subshell, so that had better not > be within a loop with many iterations. > > > if [[ ${options[invalidoption]:-off} == off ]]; then > > That's fine if the script needs to work on zsh only. Not very intuitive, > though. The «:-off» is just there in case 'set -u' is in effect. If that's not a concern, the code would be «[[ ${options[invalidoption]} == on ]]», which may be somewhat more bearable. Cheers, Daniel