zsh-users
 help / color / mirror / code / Atom feed
From: "Mark J. Reed" <markjreed@gmail.com>
To: Ray Andrews <rayandrews@eastlink.ca>
Cc: zsh-users@zsh.org
Subject: Re: exit to shell from nested function calls.
Date: Fri, 17 May 2024 12:46:36 -0400	[thread overview]
Message-ID: <CAA=-s3xNHk6ATKHk-G2S4TO-=Z-5+k_paYN0n1xmE8bP9sDnNA@mail.gmail.com> (raw)
In-Reply-To: <4b8449d3-7dfe-4d37-9c6d-1dcf63d1d9b1@eastlink.ca>

[-- Attachment #1: Type: text/plain, Size: 1036 bytes --]

On Fri, May 17, 2024 at 11:58 AM Ray Andrews <rayandrews@eastlink.ca> 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 body
> 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 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 written about a
thousand little personal utility scripts that live in my ~/bin directory.
I've only accumulated about 50 functions.

-- 
Mark J. Reed <markjreed@gmail.com>

[-- Attachment #2: Type: text/html, Size: 2240 bytes --]

  reply	other threads:[~2024-05-17 16:47 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-16 14:21 Ray Andrews
2024-05-16 20:26 ` Roman Perepelitsa
2024-05-16 21:28   ` Ray Andrews
2024-05-17 15:40     ` Mark J. Reed
2024-05-17 15:58       ` Ray Andrews
2024-05-17 16:46         ` Mark J. Reed [this message]
2024-05-17 17:04         ` Bart Schaefer
2024-05-17 17:36           ` Bart Schaefer
2024-05-17 18:52             ` Ray Andrews
2024-05-17 19:00               ` Mark J. Reed
2024-05-17 20:28                 ` Ray Andrews
2024-05-18  2:09                   ` Bart Schaefer
2024-05-17 17:29     ` Thomas Lauer
2024-05-17 18:43       ` Ray Andrews

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAA=-s3xNHk6ATKHk-G2S4TO-=Z-5+k_paYN0n1xmE8bP9sDnNA@mail.gmail.com' \
    --to=markjreed@gmail.com \
    --cc=rayandrews@eastlink.ca \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).