help-bash
[Top][All Lists]
Advanced

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

Re: Good placement of bash export functions


From: Greg Wooledge
Subject: Re: Good placement of bash export functions
Date: Tue, 11 Oct 2022 18:09:06 -0400

On Tue, Oct 11, 2022 at 09:59:30PM +0000, uzibalqa wrote:
> ------- Original Message -------
> On Tuesday, October 11th, 2022 at 9:21 PM, Greg Wooledge <greg@wooledge.org> 
> wrote:
> 
> 
> > On Tue, Oct 11, 2022 at 09:06:13PM +0000, uzibalqa wrote:
> > 
> > > A have a number of bash script files, each with its own set of functions 
> > > that a user can call.
> > > Each files focuses on specific tasks (for instance. comint.rc handles 
> > > parallel versions of
> > > search for both find and grep). So I call the whole collection a terminal 
> > > shell "package".
> > > 
> > > > What are you trying to do here?
> > > > 
> > > > How do you actually run these "script files"?
> > > 
> > > I source the files. Then users can just call the functions they want, 
> > > without having to worry
> > > about specifying any paths.
> > 
> > 
> > Ah, so they're not really scripts. They're files intended to be
> > sourced.
> 
> Would you suggest extending them to allow their use as scripts as well?
> The idea for sourcing is convenience on the command line. 

I would very much *not* recommend exporting functions from an interactive
shell so that they can be used in a script.

A script should be a standalone program, to the largest extent possible.
You should be able to run "myscript" at any time, from anywhere, and get
the same results.  You shouldn't have to populate your environment with
functions that the script will use.

If a script needs to use functions from your package, the script should
source your package's file directly.



reply via email to

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