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_AU,DKIM_VALID_EF,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,HTML_MESSAGE,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED 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 3FB3C22316 for ; Fri, 17 May 2024 18:47:28 +0200 (CEST) ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1715964448; b=CarfO7N2j6kw0bCPZnAW1mZ8n1HHgSijOy5xjZr0d6RthoS4wgt0gwI1VSmwbb/3VED5ng7eTx 07pVX+y4XpNuN72J1+3ac6NT3NvUWvaY6L0C0TfnXkk1wOZE9Za5gr6MTLnh45gJ2gL2RvYYo6 qj6rRt4jp3M5g0gDG6twAIvL8SpS22HS9AqZECmRPDNqLAniDDEOtvsHx8JgzWfK9ggQdGM9+3 sh/9KOsOIVFM550ahFxstXcG/brHzzKMx3vsJOaq9BxXuSoX4S8anTesPQj5ajUJZ8XTlrLzZO 1lg9sb6m1k4bS0R7IWDEIg5PGOnEI6xFk5EonkuOo9KhYw==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-lj1-f174.google.com) smtp.remote-ip=209.85.208.174; dkim=pass header.d=gmail.com header.s=20230601 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1715964448; bh=s6jnQAFDp+0ORhI0to7woey5/lmoOYS+6I4vfrVkIqY=; 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=WWO36KwnSw9AcpiwUy0ndNSZ+GVHy/tzzPgXRUDqYRHNfntdUrvASMMVlaM3ge4j4o5l/JFebW uXtmY8PY8MHIk7uV1gjDWMVUXlXokPlCCu6stvKz8ytMEwtDq6yv4fMki4xePRnk/X1K7D/0bn sNjYYvpU8uCvxwPhUrLLnFyoQPPuPczuMj4sFAuBkOerAdenh3b4y9ZdnVTk4z/Zg+iwtJQLwo RkwB7yS/357POq2qLqvgIkoeeztPeX/wdugW53vXorks/GRT4x25Mi8jrEFJA+0dwOeKwBcb7s NADwR2T13UuJHdVwS+aM2gTm3iCZ7hs5qf9UnNNT9mTSnw==; 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=hYpi/UOGVvwQc3c7UoRI/uWeJGXpFqd+j6Zh0keB89A=; b=lA1vRA8sLBjGUBdoj/F1onA/aa ky0M1vTWPgz+5p8vOcXpKIvOxyP6nsd4UBHVJ0q+XFaAGAtDjqZhTwSvBQfOhkNHVIONX+6hwssJe 7ECY/ywhIjgNosqez0OysrMMKq+CI/cY0jYVs5y/AMhrfOiMGxi5OA/SQfn+MgcMbBM3yH6+o8Szf uPtvFZsKfTHG5eKBPcYWVDrBSGxp/WixwCCEJxTxndeGbcOig9Ga9EnTsnfCsBZWW2WVa05dRM1Q8 5AJndWdYkACRuCbXsrsTv7yCiHxFZzlYAQaoxn8XjmUpW+lD5fhGhK8acXgUVqcG/+o9D9xeEN/G/ 9agh/xKg==; Received: by zero.zsh.org with local id 1s80jv-0000i9-Ps; Fri, 17 May 2024 16:47:27 +0000 Authentication-Results: zsh.org; iprev=pass (mail-lj1-f174.google.com) smtp.remote-ip=209.85.208.174; dkim=pass header.d=gmail.com header.s=20230601 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none Received: from mail-lj1-f174.google.com ([209.85.208.174]:53628) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1s80jJ-000PzU-En; Fri, 17 May 2024 16:46:50 +0000 Received: by mail-lj1-f174.google.com with SMTP id 38308e7fff4ca-2e6f51f9de4so11508841fa.3 for ; Fri, 17 May 2024 09:46:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1715964408; x=1716569208; darn=zsh.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=hYpi/UOGVvwQc3c7UoRI/uWeJGXpFqd+j6Zh0keB89A=; b=l2yzp2HaUhi677WM/mERj4hLSZ1Hv08wUABN+tR+m8GrGcImBz2fy71WyXoDwjHPv/ /cJBoRLsvBhN6PDOzPUYYoyruU2Ws6oSob43pS3COHaA+vzPnuyoJaA6tJjnbl5aF6vR ksAB+/E4+8r24fwF24OgaQr+UlLfy7qh7/d4AiM6mvzT5ry/ub39UDdw0s79ZHRS9TvR mcQ2NVswn1VxLxINqUixtdDyYTKsUjx+B2EDHZwOFvZl/JYoEDbZdVJjlSljC0P9OVYV bOru7bSFP0ppl9pPukKrrVIQpWNpmiZo7XGDQoFl+OEwJhtEqlr/aMlxiQyJyT7yQx4r 04Pg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715964408; x=1716569208; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=hYpi/UOGVvwQc3c7UoRI/uWeJGXpFqd+j6Zh0keB89A=; b=bEhKIy/eWgnk8i0fNnzlCZiuOuEXrvs8n5z6plMMNSnfrJ+oH88j/mQQdFSl1L5n4w gYD+pmlkR276gRbqr/QMiKcAO2HZizfd+K/UoiRe5IG0id2pyh9h8ug53lqrKQPL5fmH 0blLoeVFk8bOn3nAbxS3tbkLZDaTGRU8EEqE+oL0IVlSmJkyhbLUsdscFHRLSLNtHkQK wfEIO8rpkpMdmA1uNCmbw+rVp0/XpgsQmgYh3BS91cmDk3XIEmA70uPq+w9UcNd+TqVd FXA/aj5nNt8tOzJ2Lw9pQmXMHre4O3rMt/BTRxMoHCvGP+vfOlIIS2TuEE6dNwMncJIl Xigw== X-Gm-Message-State: AOJu0YzbMNf1NcF/FNGBpv6WC53wpv7Mhwe95Wkfhbjvt26ExUnaWGr6 WdN3K0Sq1s/6Dg1tYMsr76GrhsMquQdSFuL0/ezsO45Y94ZJWKn9rJvpTGTSEmxbf4eCm3fVSdk Q7WRjlN1ylFl/3IT98gq3qYlcRpg= X-Google-Smtp-Source: AGHT+IHcoT/W8i8LHh/B9Ty9rUL4ITldbvL1LWpibH6uSE36Hkqu8eHJu8Bib13gFN9wLAFA0kYKNsMcgZyslWdh/IE= X-Received: by 2002:a05:651c:a0f:b0:2e2:812:4c4 with SMTP id 38308e7fff4ca-2e51fe57d49mr213731811fa.29.1715964408226; Fri, 17 May 2024 09:46:48 -0700 (PDT) MIME-Version: 1.0 References: <9b97bc99-1d92-46f1-8841-c757d1dcee68@eastlink.ca> <09115b25-9017-4233-aaf2-6e4378aba53f@eastlink.ca> <4b8449d3-7dfe-4d37-9c6d-1dcf63d1d9b1@eastlink.ca> In-Reply-To: <4b8449d3-7dfe-4d37-9c6d-1dcf63d1d9b1@eastlink.ca> From: "Mark J. Reed" Date: Fri, 17 May 2024 12:46:36 -0400 Message-ID: Subject: Re: exit to shell from nested function calls. To: Ray Andrews Cc: zsh-users@zsh.org Content-Type: multipart/alternative; boundary="000000000000fff1050618a91840" X-Seq: 29941 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: --000000000000fff1050618a91840 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Fri, May 17, 2024 at 11:58=E2=80=AFAM Ray Andrews wrote: > On 2024-05-17 08:40, Mark J. Reed wrote: > > Functions are great, and I recommend using them - just use them _inside_ > the script. For anything but the most trivial scripts I make the main bod= y > of the script a function, too, something like this: > > #!/usr/bin/env zsh > main() { > main program code here > } > > Just remember the *main "$@"* at the bottom, otherwise you've got a script that just declares some functions and exits without calling them. :) > Only define functions inside your interactive shell when they need to mak= e > changes that persist after they exit - like changing directories, or > updating variable values, etc. > > That would limit their number considerably. > Indeed. As a point of comparison, over the years I've written about a thousand little personal utility scripts that live in my ~/bin directory. I've only accumulated about 50 functions. --=20 Mark J. Reed --000000000000fff1050618a91840 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
On Fri, May 17, 2024 at 11:58=E2=80=AFAM = Ray Andrews <rayandrews@eastli= nk.ca> wrote:
=20 =20 =20
On 2024-05-17 08:40, Mark J. Reed wrote:
=20
Functions are great, and I recommend using them - just use them _inside_ the script. For anything but the most trivial scripts I make the main body of the script a function, too, something like this:

#!/usr/bin/env zsh
main() {
=C2=A0 =C2=A0 main program code her= e
}
Just remember the main "$@"= at the bottom, otherwise you've got a script that just declares so= me functions and exits without calling them. :)
=C2=A0
Only define functions inside your interactive shell = when they need to make changes that persist after they exit - like changing directories, or updating variable values, etc.
That would limit their number considerably.
=
Indeed. As a point of comparison, over the years I've wr= itten about a thousand little personal utility scripts that live in my ~/bi= n directory. I've only accumulated about 50 functions.
=
--
Mark J. Reed <markjreed@gmail.com>
--000000000000fff1050618a91840--