From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_EF,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 Received: from zero.zsh.org (zero.zsh.org [IPv6:2a02:898:31:0:48:4558:7a:7368]) by inbox.vuxu.org (Postfix) with ESMTP id C9A3928848 for ; Tue, 5 Mar 2024 08:09:42 +0100 (CET) ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1709622582; b=WxOZQ6lTxqAkjqIi5L0gss5dDwwRwNLEujVDa3+2U4xaNWyUAmrbpseIeZ3Pt0Fv/HeV3FtK/n 51ZccNhhHh8jmw6aTGD2bp+sos4mo43Ug+6Ciy+KPlHOlR0f77daguCNjehyyDBNIkisSH0E6e 3kl6lPz7PPno4kw61q2gNZYxL5QgXom23pdfN6WUMHdsRqHCjiq2xdgowA+kDX8e0fBy6d/wfa enhWkT2sHadReDYNOvzfFhG71BAOjp53EAxUfV2+MWDecrvxoIyk36zkq7eAyjFXsRsmsl/TTS n7vVAYpqOYYGRVFYbeqCr8nOuXhnTu522rgXKYTeXX8rKQ==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (relay7-d.mail.gandi.net) smtp.remote-ip=217.70.183.200; dmarc=none header.from=chazelas.org; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1709622582; bh=1n5tOdPZdLFIBx7OV9GwvjHoavRqICX2VZE3B1+3uaU=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:In-Reply-To:Content-Transfer-Encoding:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:DKIM-Signature; b=BE/q5LI7cLfVR0/NVbB63My7QGWJDRY2tBqGS1XCUI4ZPBbRY5oeyBs4OWo7q2Fj3ZnAwxpPL7 1l+nsf7yG3zmgyWJXXeJ7oiIPnrcQun/yActL/7DY2aFyh5bgHfwjF5R3/sQGDR6ihnv4KxINr aYkpoIqCyIZYJXX+XxcMRCcowJt5vAYBPT91EgRmKS6LmFLza3bpWLEwPdCHEy8EPWK5IqOWCa WfMk8laBQetiJvJjRUoVDbOfjAKDlaC8fv7HK/Smf61gx/YuSZISfD5UxiLPM2l+Bl65uFxwmq rVAhvkS0VD3l/bqBn2M7ExTWEcO2WDEsT4ETQ+4MEmBJ7w==; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20210803; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:In-Reply-To:Content-Transfer-Encoding :Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To:From:Date: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID; bh=er7pTrX+tAuaEXf8YKGrhhS1wKFYtFnl6lnMpoFaeTY=; b=U8e+tIDIldHDPJmh4TOX4tq9V9 i+E2dq0EHYiBT8ERyYqyf1A/gLbuxxfk54tCJwqnv4DpdQLnVY1O9vW/jQzoK6asVmK0nFc2vFzJz IqoXaXkuzrPfsCBWLDjOaQajMbGulIezdYH/+eMtaB2qiA4/qK0S4UDra6RTnHhXcEhLMHJ1Hl1pq GrrcMI5+uT0dLDqRlEZ0SjlHxoAKYYamSLpPY6RFKB4AEtzQcXUTNnT0upevSaTVCuI20td7Bp/I2 5WN040RUfN00nb9BbgPOACv3TWvdtPvvK/MNwughm7Jh0HloaQ06lHz/XvOYFUzC1OBQAjE1w6BI+ 13MlvuXA==; Received: by zero.zsh.org with local id 1rhOvm-000Ljt-8h; Tue, 05 Mar 2024 07:09:42 +0000 Authentication-Results: zsh.org; iprev=pass (relay7-d.mail.gandi.net) smtp.remote-ip=217.70.183.200; dmarc=none header.from=chazelas.org; arc=none Received: from relay7-d.mail.gandi.net ([217.70.183.200]:47049) by zero.zsh.org with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) id 1rhOvG-000L3Y-1w; Tue, 05 Mar 2024 07:09:11 +0000 Received: by mail.gandi.net (Postfix) with ESMTPSA id C3B9920008; Tue, 5 Mar 2024 07:09:08 +0000 (UTC) Date: Tue, 5 Mar 2024 07:09:08 +0000 From: Stephane Chazelas To: sergio , zsh-users@zsh.org Cc: Bart Schaefer Subject: Re: Arithmetic Zero Message-ID: <20240305070908.rxv4tc6at57arb6t@chazelas.org> Mail-Followup-To: sergio , zsh-users@zsh.org, Bart Schaefer References: <47117922-e17f-44d1-8a2f-2cb4a9c53606@outerface.net> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-GND-Sasl: stephane@chazelas.org X-Seq: 29718 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: 2024-03-04 20:23:51 -0800, Bart Schaefer: > On Mon, Mar 4, 2024 at 7:28 PM sergio wrote: > > > > I believe -e is best practices for scripts > > Leaving opinions aside ... [...] https://mywiki.wooledge.org/BashFAQ/105 https://fvue.nl/wiki/Bash:_Error_handling https://mywiki.wooledge.org/BashPitfalls#set_-euo_pipefail (for bash but most of it applies to other Bourne-like shells) are good references about the problems with errexit. One might add that using option names rather than letters is preferable as more legible (and more portable like for -f vs noglob where -f means something different in zsh and other shells), and that it's preferable to set them via "set" rather than via the shebang as the shebang is not honours when the script is invoked as zsh path/to/the/script or source path/to/the/script or zsh < path/to/the/script and on most systems, shebang can have only one extra argument and using options there prevents adding the option delimiter. So: #! /bin/zsh - set -o errexit -o nounset -o pipefail (or setopt if you prefer but I like set -o better as that's supported by many other shells) Rather than #! /bin/zsh -euopipefail Of those 3 options, nounset is the least controversial. errexit is a minefield and pipefail can be problematic when using pipe consumers that exit (successfully) without reading their whole input (where a death by SIGPIPE of the feeder is not necessarily a failure. Best to do proper error handling. I usually define a die function for that: die() { print -ru2 -C1 -- "$@" exit 1 } cmd1 || die cmd2 || die "some error message" -- Stephane