bug-bash
[Top][All Lists]
Advanced

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

Module systems for bash?


From: Jon Seymour
Subject: Module systems for bash?
Date: Sun, 24 Aug 2008 17:16:03 +1000

Forgive me if there is a more appropriate forum for discussing this
topic, but it wasn't obvious from a cursory glance at the web pages
that there was one.

I was wondering if anyone has ever developed a module system for bash,
similar to the system that Perl has.

I have been been using a rudimentary, home-grown module system myself
and I find it to be quite an effective way of developing, maintaining
and distributing useful libraries of bash functions within the
confines of a project team.  The next logical step would be make the
system truly scalable so that it was practical to import modules
developed independently by third parties.

I think bash is a particularly useful language to develop libraries of
utility functions. In my view, it is superior to perl because it is a
shell language - any constructs used in the shell can be used in the
script library and vice versa without any impedance mismatch.

The way I achieve this is to expose each function in the script
library as an alias in the shell. The alias invokes the wrapper script
that loads the script library and then dispatches a call to the
function as the same name as the alias. In this way, all the functions
of the script library are directly accessible from the command line
allowing them to be composed at will in useful ways.

This leads to a very functionally rich shell and minimal redundancy
since function implementations can themselves re-use other functions
in the library.

My initial implementation has been a little too successful in that I
have thousands of small functions in my library and load times are
starting to become noticeable because I haven't paid enough attention
to the scalability aspects of the module system. The next generation
will fix this, but before I spend too much effort re-inventing the
wheel, I'd be interested in learning of other efforts in this area.

jon seymour.




reply via email to

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