Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

exportable functions

350 views
Skip to first unread message

Thomas M. Breuel

unread,
Sep 8, 1989, 4:54:05 AM9/8/89
to
It would be nice if Bash supported exportable functions like V9 "sh".
Strings of the form "name=value" in the environment are considered
environment variables, and strings of the form "name(){value}" are
considered environment functions.

Thomas.

Chet Ramey

unread,
Sep 8, 1989, 12:05:37 PM9/8/89
to
In article <8909080854.AA12325@rice-chex> t...@AI.MIT.EDU (Thomas M. Breuel) writes:

(Don't you love how the AI lab named all of their machines after breakfast
cereals? :-)

Funny, Doug Gwyn and I were having a discussion about this just last
weekend on comp.unix.questions.

The problem with the v9 syntax for exportable functions is that it requires
a C library `getenv()' that ignores the definitions and shells that
understand them (for example, this would choke a "regular" System V /bin/sh
started under bash -- either you would have some very strangely-named shell
variables, or the shell would just get all confused).

Bash does have exportable functions; the syntax is "name=() {value}", which
I think is a nice compromise:

kiwi$ echo $BASH_VERSION
1.03.59
kiwi$ type foo
foo is a function
foo () { echo this is foo }
kiwi$ export foo
kiwi$ bash
kiwi$ foo
this is foo
kiwi$

Chet Ramey
Chet Ramey "We are preparing to think about contemplating
Network Services Group, CWRU preliminary work on plans to develop a
ch...@cwjcc.INS.CWRU.Edu schedule for producing the 10th Edition of
the Unix Programmers Manual." -- Andrew Hume

Brian Fox

unread,
Sep 8, 1989, 12:21:24 PM9/8/89
to

From: t...@ai.mit.edu (Thomas M. Breuel)
Date: Fri, 8 Sep 89 04:54:05 EDT

Bash 1.03 can export functions to other bashes.

Upon reading in the environment, if a string of the form "name=() {" is
found, then that is a function definition. Perhaps I can support the
other syntax as well.

toplevel$ foo () { echo bar }
toplevel$ export foo
toplevel$ printenv foo
foo=() { echo bar }
toplevel$ bash
bash$ type foo
foo is a function
foo () { echo bar }

Brian Fox

0 new messages