[Top][All Lists]

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

Re: Issues with exported functions

From: Steve Simmons
Subject: Re: Issues with exported functions
Date: Wed, 24 Sep 2014 21:27:45 -0400

On Sep 24, 2014, at 4:06 PM, lolilolicon <address@hidden> wrote:

> On Thu, Sep 25, 2014 at 3:53 AM, Greg Wooledge <address@hidden> wrote:
>> So, if Chet removes the feature, it would probably break something that
>> someone cares about.  Maybe there could be a compile-time option to
>> disable it.  Maybe there already is -- I didn't look.

Many bash completion libraries also rely on function exports.

> I don't expect more than a dozen who rely on this... but bash
> programmers can be quite the perverts, so...

A significant number of us have actually read the manual and rely on the 
ability of bash to export functions. I have literally hundreds of exported 
functions in my environment. Some are defined in a setup file '~/.bash_once', 
some get built on the fly by that file. As you might guess, ~/.bash_once is 
invokes only once per session by my .bashrc &.bash_login with something like:

if [[ 0 == "${SET_ONCE:=0}" ]] ; then
    if [[ -f ~/.bash_once ]] ; then
        . ~/.bash_once
        echo "No ~/.bash_once file for '~/.bashrc' to invoke." >&2

.bash_once defines SET_ONCE and loads literally hundreds of environment 
variables and exports many shell functions that would otherwise have to be 
defined in .bashrc and processed on every freaking run. .bash_once is about 50 
times larger than .bashrc and .bash_login. Fast. Very fast. But without 
exportable functions, it wouldn't work at all.

As an exercise for the student, consider the utility of this simplified excerpt:

    for SYSTEM in \
        {foo,bar,baz}.dec.school.edu \
        {alligator,snake-skin,lizard}.reptiles.work.com \
        {misery,serenity,frailty}.films.home.org \
    ; do # Strip off domain, use dash-less name as function name
        export FNAME=${SYSTEM%%.*}
        export FNAME=${FNAME//-/}
        eval $(echo "$FNAME() { ssh $SYSTEM" '"$@";};'" export -f $FNAME")
        unset SYSTEM FNAME

Hint - source those lines, then give the command 'builtin type snakeskin'.

It's probably too much overhead for every bash invocation, but if you only do 
it once per session, it's damned useful. 

Consider this one vote against removing function exports.


reply via email to

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