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 0A90F2223C for ; Fri, 17 May 2024 17:41:18 +0200 (CEST) ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1715960478; b=nqMHyxrm9Dej4ninMbqMAP6KEiqgDBZ2TyJPGDMd9O3p/ZniV7VB+evZRFXIZWmcThk007BU5E 2FTH1/G/VTS0TCU7lZgBGX+wLbVVLmpK5GHclUWCsRk8BXnm8uZJSVGQxE8kiixQwt5SUnSViD aL9HUgLVa0sx3OGCCXBQ0NCswePJaSkchuRo9EI1UjO102ASg3XJeAR42yX51A/zc2Od7Z/o5V I2KUi9B/zjPd94aIhPcSu2drncUgJF3XE1XmWGjZTBovDnFiB57tY+jiIEtMuKafHtSZS4oWKU DX/frBt4LO2C4qhl4yW34Oscvg7X2OTUmGE/VtzZxvCEKw==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-lj1-f179.google.com) smtp.remote-ip=209.85.208.179; 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=1715960478; bh=uo1gM17CGdTDfolTuASJfpUrxfaGHTu4G9kTTE4BKVQ=; 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=L2Ig6eyMZhFg2+pVtdmYhe957MvXgtrbRBWZ/LKLeHO4VS5ube5Iy0+TzNmPa6j6FW3Lq6gjqv OI5xqfTrClx53tugmHO6lqYvF24dBSIu+0s6LCz1Csm39WtfIGbJGCv5oqDYMQ+z/fY9Xq4De3 hJikNe21zskc7tpOMx9DDWDGP3blrPi5Y3uJoL1HCrVfI1q6K+pjposrA8G220aN2ER6/x8gHK 18kpt3HVkpHlFzkbVgAV81zlUpxQNPUG/junM/5u3qptm2c/iq+bMEcsInx3oIfADWXRAbP+yN OPBpCa3lU8Bbm/6JUUrYDIvNdgtlDkSmzj4w3M48BmN0jg==; 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=zbBwp5eRSdqbZvuT5uV2h7IW323C+EpWTJEy5JvuSso=; b=feaybgXWwBKNajxIuWfS7Vne1y SbLioa2KxD/Wnpq1zQtKE33oGWUksZWQ0pDuUx17BSSU9M75+50U9LSHsBkdACAqGijUWXfhiEKjM JZzICiXNzWk2lv2sJ3U350R3AbsP36ELtljHV+Q3nT5Ih6Fy2PI6PKFMcXTJzyxjclYZdRG5s6UA/ z/Fzjav5yBHSk9EZ/Ac+SJgQRv7b54Z1Y3niVc21gq+56QRrFRNsLHQNdeQCmJqKuojz5sCaTy0ay zril8be4irmv9ufdoJzSkY+Y6TUPQ+Sed8KDefVrh84Mtu2b+oLtqqFvMvy2WzmIOw0+NbFsGojrT eZ6DBxyw==; Received: by zero.zsh.org with local id 1s7zht-000MiK-KL; Fri, 17 May 2024 15:41:17 +0000 Authentication-Results: zsh.org; iprev=pass (mail-lj1-f179.google.com) smtp.remote-ip=209.85.208.179; 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-f179.google.com ([209.85.208.179]:43336) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1s7zhC-000M0i-UF; Fri, 17 May 2024 15:40:35 +0000 Received: by mail-lj1-f179.google.com with SMTP id 38308e7fff4ca-2e1d6166521so17173491fa.1 for ; Fri, 17 May 2024 08:40:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1715960434; x=1716565234; 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=zbBwp5eRSdqbZvuT5uV2h7IW323C+EpWTJEy5JvuSso=; b=Db1OZX9xLPt5lSWkv6mOCRbJcVDK9c1+1mA0mjgnec5lYQouSN//stls2wSIo52cab WT43aBKkuxz9uCA7gcm8WrGFLKMHfos+JRxLVNMk7/GmbDUscZKIWvwZhRpcZyD1bbea UXAlMIHLpPop0SZfeb/494bOfcAepInQovIU6T1O3iwH5GqaQZ6gZc6MiQzew/NfDJv/ uxlHRyWyueJy0F+iW1r/IKh1b/0A+7r1B2oIKgQCUzSw69D0Uc7H2jQK8TmO2VwTAejz nwQn7KWHC9JU+YaniJgcmwWon4bun6y9nBYuqlbUGut0gYlur40eAKhpjZ7dmY/UALH6 3p1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715960434; x=1716565234; 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=zbBwp5eRSdqbZvuT5uV2h7IW323C+EpWTJEy5JvuSso=; b=DtN1Uz0PUdOQnHOgmL/cCzCozQR6TZ9v2mwf0DCYJ33pMdHt7VWosNxF8OpEPx3x3N 0mWeaHgXhbA79017/u0OspNovEDu0sHzUAPZKb87BzdzpOPv/yx07SPkvSRzuER3lfgb 6k8tK2qeKbFgLcq2MlvnqBvCEJ5SxYK4M5Tntpgfnio36koob1tauj347kvOopD8VWDB OFBC/q1gkcd/rgs6HWrBalor+GmnbgYHUEZJvc6PLhRbnhNu3TTb0SY94asPfVsurJ5j iuI25kAdafklC3uPMk7UMRwMeQoyyERw5r3fGKJw7Vzd+8AZWA25qFfuVIynqJ+fIDeF 7jXQ== X-Gm-Message-State: AOJu0Yw1tBIatOE7qvmxmxD2299I0q9cnOZtmMvFcPOjnqhrlr04Rt3B sBYOP1o0KJiWr5+lnGNRKWgcLKUWwfnLarwxbPZzBFO6Zp7tJyZL21nQf/VDCEm847QFp1tDmSK kDUy87k99lN3UMO3PKPwhkWFCh9g= X-Google-Smtp-Source: AGHT+IGMEOLBbDMmkmipZc6uIm9XjocrkrovosSg2d5RgKB5NNWNsYKiU88KH6utmSNJuu7yMT2EkvBxyiosMir6p0w= X-Received: by 2002:a2e:96d3:0:b0:2de:6f52:5c8d with SMTP id 38308e7fff4ca-2e51b4784abmr77793491fa.21.1715960433716; Fri, 17 May 2024 08:40:33 -0700 (PDT) MIME-Version: 1.0 References: <9b97bc99-1d92-46f1-8841-c757d1dcee68@eastlink.ca> <09115b25-9017-4233-aaf2-6e4378aba53f@eastlink.ca> In-Reply-To: <09115b25-9017-4233-aaf2-6e4378aba53f@eastlink.ca> From: "Mark J. Reed" Date: Fri, 17 May 2024 11:40:21 -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="00000000000019b7ff0618a82c14" X-Seq: 29939 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: --00000000000019b7ff0618a82c14 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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() { main program code here } sub1() { called by main } sub2() { called by main or sub1 } .. ... other declarations ... ... main "$@" 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. On Thu, May 16, 2024 at 5:30=E2=80=AFPM Ray Andrews wrote: > > > On 2024-05-16 13:26, Roman Perepelitsa wrote: > > I'd turn this into a script (executable file) and use exit to bail > > out. IMO, anything that can be a script is better off as a script. > > I'm slowly figuring that out. Yes, that's the motivator I need. Coming > from C I just sorta started writing functions cuz that's what one does in= C. > > Thanks Roman. > > BTW, just in case you're wondering, it's an overlay for mostly firefox > which chatters to the disk almost constantly. Got a newer machine > recently and it has a SSD, but I know they have limited R/W cycles so I'm > using the overlay to deflect the chatter to RAM. Works good so far. Wil= l > try it with a few other progs too, and possibly /var. It 's interesting > watching 'fatrace -fW' for a while -- see who's a disk blabbermouth. > > > > --=20 Mark J. Reed --00000000000019b7ff0618a82c14 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
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 here
}<= /div>

sub1() {
=C2=A0 =C2=A0 cal= led by main
}

sub2(= ) {
=C2=A0 =C2=A0 called by main = or sub1
}
..
... other d= eclarations ...
...
<= div>main "$@"
<= div>=C2=A0
Only define functions inside your interactive shell wh= en they need to make changes that persist after they exit - like changing d= irectories, or updating variable values, etc.

On Thu, M= ay 16, 2024 at 5:30=E2=80=AFPM Ray Andrews <rayandrews@eastlink.ca> wrote:
=20 =20 =20


On 2024-05-16 13:26, Roman Perepelitsa wrote:
I'd = turn this into a script (executable file) and use exit to bail
out. IMO, anything that can be a script is better off as a scrip=
t.
I'm slowly figuring that out.=C2=A0 Yes, that's the motivator I= need.=C2=A0 Coming from C I just sorta started writing functions cuz that's wha= t one does in C.

Thanks Roman.=C2=A0

BTW, just in case you're wondering, it's an overlay for mostly firefox which chatters to the disk almost constantly.=C2=A0 Got=C2=A0 a= newer machine recently and it has a SSD, but I know they have limited R/W cycles so I'm using the overlay to deflect the chatter to RAM.=C2= =A0 Works good so far.=C2=A0 Will try it with a few other progs too, and possibly /var.=C2=A0 It 's interesting watching 'fatrace -fW= 9; for a while -- see who's a disk blabbermouth.=C2=A0





--
Ma= rk J. Reed <mar= kjreed@gmail.com>
--00000000000019b7ff0618a82c14--