bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [bug #68131] Shell script misbehaves when edited


From: Zachary Santer
Subject: Re: [bug #68131] Shell script misbehaves when edited
Date: Mon, 9 Mar 2026 20:02:16 -0400

On Mon, Mar 9, 2026 at 11:24 AM Stan Marsh <gazelle@xmission.com> wrote:
>
> There *are* scripting languages that read in the entire
> source at startup and build an internal representation which is then
> executed.  These languages then don't care if you mess with the source
> while the script is running.

Keep in mind, if you want this behavior, it's not hard to get.

You can literally just enclose your existing bash script between a
pair of curly braces to force bash to parse the whole thing before it
starts to run it.

Any script I write with any function ends up looking like this:

set # options
shopt # options
unset CDPATH TMOUT

# readonly global variables

main () {
  # do things
  exit 0
}

func1 () {
  # do things
}

func2 () {
  # do things
}

main "${@}"

Because the call to main () is the last bit of code in the script,
everything has been parsed before it runs there too.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]