From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.3 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 23735 invoked from network); 6 Aug 2021 21:08:57 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 6 Aug 2021 21:08:57 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1628284137; b=Yshl9uHipIRi3oTNLMkGv0jCdZ/Pan+ir0U4ep4y2N01e45J0XbIRAMGx4VoHATq4Hi/aJS5J4 5v+L5RzGDyULoTqmUShdYV94446MoDOXM70pcdolfsOYKuGX+jxeC/t+oLpC/E6L481te8W4EM fuBzirlzNtOdRodXfYkZt058nuBymIWEADFElQuX3J6P2hs2JMHseP7ee90t4lrSm5hmq5EuGQ yVRcePcN0kAP/iuZkQfpbPsEbci8iuqt5pR9P1GaWe9wx/N3oXx9U5XHKixFLgkA6hN7bkrH20 kFfxRJntSiHQO+jJnQTBXsdqwPwPX7V1nF0aj7ko6z+Gyg==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-yb1-f178.google.com) smtp.remote-ip=209.85.219.178; dkim=pass header.d=brasslantern-com.20150623.gappssmtp.com header.s=20150623 header.a=rsa-sha256; dmarc=none header.from=brasslantern.com; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1628284137; bh=/E2IU809HCyNceEs5iHiOWVR7LJZJlhWpAmkubgGcFE=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Type:Cc:To:Subject:Message-ID:Date:From:In-Reply-To: References:MIME-Version:DKIM-Signature:DKIM-Signature; b=NPLd70se66W6ALU+5VCa/vDK1kGcSQLk2roLEyRyXHZPPwBIpGUGgx68Mirr5uz5rL88+kJHs+ wO0mTRP9MsLvrJYrkXiuOSabbZ53IFXKv+qcYGSLNc4zjopXYP/TohIJgQODS2ok6K3rgIcuVW HojcnN44tK6fFdav0zzG2MsR7rR2EFXQordJ8lq83eZHE/Lur2yETQ8QqD0HF0YQUq2VmwdFeg wt567DnUoZFryDQGCyYH5mKvCHvWkh4C+AT23SdXZ4wgNdQ9fMR6c9hVTLn39XKGJYp8B4K9h7 z+H0ia4y0oTpsCRh2cquHoDFHU0hiG6ane0nIss71a5aPg==; 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:Content-Type:Cc:To:Subject:Message-ID :Date:From:In-Reply-To:References:MIME-Version:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=A1pEBYME1G4yKrArLeVpLKzH13cNn10EsV4NqR3IiqQ=; b=rsn1F8mKUynZBSNpbXI9kkqdPc KqYzaBdxorFe/bUoUMxxuQEnOrAG4qZ62TvvVs8Y7BMyFbZBe7AcN/+HDDdTAOTqJ/Rk9TkLiB3iE wsk3smxjw+5gHojTeMTeCNrNk5bk7DnHHTLftfOaNEzNzuFv0Hp++/51z4yAl8ed7AZ1sL9IpBn1s VYD91sx++k98dwwhrGndMYN5h+9xixJ5ak4NaiRao2HhztiXK7pNhgpQ28FQ0qkhGQdkd+6fvsOlv jSGHag5chV1WKuo2f+UgEeAAp7wQTlbTSp7wMOHRVThIn6FVaAQ9qCFc1hXuzlbIwgIyMNfKt0Cj6 ynBln/9w==; Received: from authenticated user by zero.zsh.org with local id 1mC75M-0008jZ-HC; Fri, 06 Aug 2021 21:08:56 +0000 Authentication-Results: zsh.org; iprev=pass (mail-yb1-f178.google.com) smtp.remote-ip=209.85.219.178; dkim=pass header.d=brasslantern-com.20150623.gappssmtp.com header.s=20150623 header.a=rsa-sha256; dmarc=none header.from=brasslantern.com; arc=none Received: from mail-yb1-f178.google.com ([209.85.219.178]:43561) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1mC74Y-000820-1s; Fri, 06 Aug 2021 21:08:07 +0000 Received: by mail-yb1-f178.google.com with SMTP id z128so17456445ybc.10 for ; Fri, 06 Aug 2021 14:08:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=A1pEBYME1G4yKrArLeVpLKzH13cNn10EsV4NqR3IiqQ=; b=FdpLuEx2VMqx1bs6OH9bvRhXFWpMVgSUYl9w0Ccdzoyk+LRapDmLQMVPBMfKsmxcX0 Dq1n5ldd3B95ZsyHDRzYIhXx9+ZnyH24V6CLiNkhCUiQCFbv0VCxJ5oArd8JmQX9+Jma i41ZpKCMKcOP13pi3/CfbEGB8qUBqcL86GqSvZ1gVfRJ8zYU6fchWW4nPtSCKeS0/k1g 0YXS6XN8vTsObGEOo6yW4U5GR9Pdf7ZrI9sWN1R75x4DQ8hfk0y/mZJRh0y/jGu/Dr3T YiJVa3DZa7kpPcfvQC8Q9miwW+RYUtz7uR4ii2Qm4yUEldaBrdtS8PtWogWLDw4hUZJs dYXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=A1pEBYME1G4yKrArLeVpLKzH13cNn10EsV4NqR3IiqQ=; b=HxjoR2L5rGcAAM0SUubIvtDaGD60N5xoVHi/qfkVX7QCo/T8ydVSSyVS6610OMjzho Ju5ws4a/M8fOWNiuqMmbwJspZ01MHI+JdKUOBEDs+IfRZrGVdcHv72mL3WIszMvXqz7o q5dLatgSOfcYKYAN4DoYnt93d1XVSoRCvTt5vrcUjvZEIiPZuTV/9Uua9lDS63HWd/wS sdfI5cR4i8ZXK/xR8YQXNa25Taq2o/sVs8V4A1rhPLIcNCRr92Rs/6UqKueXjlDyXqoM DGwgspeweFRf/YxxoSGKetQBe0OOgX2GsmKso96RPaIlp/67PxvK2Jq5s1BoicKfR1Zh 9OkA== X-Gm-Message-State: AOAM532HBK1zq6PNBZOGpxYLLM60cVQMQaPzstROIsCdGm9vr+AF1dRn cGfGtRkif2AFaVck/oV5h4l72nXalhrvW0T8RnnIuQ== X-Google-Smtp-Source: ABdhPJxOLhxPcYRh9V6PrGohFLLZyL3wluW1fKn8m4G+pgfFqquk0W2wXXRZ+gBKtkZrHEPHH6i+1ogwoaH8nGHjyZ8= X-Received: by 2002:a25:918c:: with SMTP id w12mr6136402ybl.226.1628284084623; Fri, 06 Aug 2021 14:08:04 -0700 (PDT) MIME-Version: 1.0 References: <9b2bd9dd-2769-01c7-8650-39eb9e260a67@eastlink.ca> In-Reply-To: <9b2bd9dd-2769-01c7-8650-39eb9e260a67@eastlink.ca> From: Bart Schaefer Date: Fri, 6 Aug 2021 14:07:53 -0700 Message-ID: Subject: Re: abort if any error To: Ray Andrews Cc: Zsh Users Content-Type: text/plain; charset="UTF-8" X-Seq: 26872 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: On Fri, Aug 6, 2021 at 11:42 AM Ray Andrews wrote: > > $ . wonderful_function; wonderful_function > > But, ooops, my last tweak to the function busted something so it wasn't > sourced and what ran was the previous version. Is there some way of > forcing any script or command line or anything at all to stop > unconditionally in case of an error on sourcing? The "." command should have returned an error (nozero) status if it couldn't load the file, so the problem is that you used ";" between the two commands. That effectively ignores the exit status of the first command and runs the second one regardless. If you had used "&&" instead, you would have gotten what you wanted. There's nothing you can put INSIDE a script file that will cause the sourcing shell to interrupt a ";"-separated sequence of commands when the script has a syntax error or other parse-time failure. If your two sample commands had appeared in another script, instead of at an interactive prompt, "setopt errexit" in that outer script would have caused it to stop when the first command failed, but that should be used carefully because it will cause the script to exit when ANY command outside of a conditional test context returns a nonzero status. You DO NOT want to put "setopt errexit" in a script you will be loading directly with the "." (or "source") commands, because that can cause the whole interactive shell to exit. Using errexit in a function definition nested in a script file is OK, but as noted above won't do any good if the function has a syntax error.