From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11491 invoked by alias); 14 Nov 2017 13:22:48 -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: 42023 Received: (qmail 24740 invoked by uid 1010); 14 Nov 2017 13:22:48 -0000 X-Qmail-Scanner-Diagnostics: from kahlil.inlv.org 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(37.59.109.123):SA:0(-1.9/5.0):. Processed in 4.748747 secs); 14 Nov 2017 13:22:48 -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=-1.9 required=5.0 tests=BAYES_00,RP_MATCHES_RCVD autolearn=ham autolearn_force=no version=3.4.1 X-Envelope-From: martijn@inlv.org X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Subject: Re: [PATCH] don't exit shell on [[ -o invalid@option ]] To: Zsh hackers list 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> From: Martijn Dekker Message-ID: Date: Tue, 14 Nov 2017 15:22:35 +0200 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 In-Reply-To: <20171114122619.kqa4i2sth66mafrs@tarpaulin.shahaf.local2> Content-Type: text/plain; charset=utf-8 Content-Language: en-GB Content-Transfer-Encoding: 7bit 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. > 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. > 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. > 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. > 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. 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. - Martijn