bug-bash
[Top][All Lists]
Advanced

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

Re: BASH_FUNC__ appearing in environment


From: steveT
Subject: Re: BASH_FUNC__ appearing in environment
Date: Fri, 28 Nov 2014 00:43:37 -0800 (PST)
User-agent: G2/1.0

On Friday, 28 November 2014 08:00:18 UTC, steveT  wrote:
> On Thursday, 27 November 2014 17:57:30 UTC, konsolebox  wrote:
> > On Fri, Nov 28, 2014 at 12:36 AM, steveT steveT wrote:
> > > Is there any way that I can trace them back to their 'creator'?
> > 
> > Besides checking common startup files like /etc/profile and ~/.profile or
> > ~/.bashrc (see 
> > http://www.gnu.org/software/bash/manual/html_node/Bash-Startup-Files.html),
> > you can also try to debug bash as it loads in login mode:
> > 
> > # bash -lx &> out.txt
> > # exit
> > 
> > Read out.txt, try to find those declarations and pay close attention to
> > lines before it that calls another file with . or source.  If you don't
> > find any kind of declaration, it's likely that those functions are declared
> > somewhere during system init and that would depend on your init system.
> > 
> > If it's me I'd just do fgrep something /etc -r (not -R unless I'm sure it's
> > safe) and see if I can find something useful.  It may still not be enough
> > though - especially if those declarations are hard-coded in a binary
> > executable or data file.  You can also consider searching through the files
> > of the base package of your init system - or even examine the sources if
> > you can.
> > 
> > Cheers,
> > konsolebox
> 
> Konsolebox,
> Thanks - I did try recursively grepping etc and didn't find anything.
> I will try the bash 'init' check, but I don't think it can be there as 
> wouldn't that imply that the BASH_FUNC__ vars would be there from the outset? 
> And, the BASH_FUNCs appear at random (obviously not random, as they must be 
> being triggered by something) points during the day - I can go hours and not 
> see these appear - I can use sudo and rcs to do various things and they don't 
> appear. 
> 
> Can I ask - is there a chance that it's something that I've done in a script? 
> Is there a setting somewhere that tells bash to export certain functions to 
> the shell or do you have to explicitly export them to see them in the 
> environment like this?

OK - found the functions that are appearing. I was grepping BASH_FUNC__ in etc 
- wrong. The functions are in the /usr/share/bash-completion/completions 
directory - and exist as rcs and sudo  files. The code in those files defines 
functions for _rcs and _sudo respectively. The rcs file contains:

# bash completion for rcs                                  -*- shell-script -*-

_rcs()
{
    local cur prev words cword
    _init_completion || return

    local file dir i

    file=${cur##*/}
    dir=${cur%/*}

    # deal with relative directory
    [[ $file == $dir ]] && dir=.

    COMPREPLY=( $( compgen -f "$dir/RCS/$file" ) )

    for (( i=0; i < address@hidden; i++ )); do
        file=${COMPREPLY[$i]##*/}
        dir=${COMPREPLY[$i]%RCS/*}
        COMPREPLY[$i]=$dir$file
    done

    COMPREPLY+=( $( compgen -G "$dir/$file*,v" ) )

    for (( i=0; i < address@hidden; i++ )); do
        COMPREPLY[$i]=${COMPREPLY[$i]%,v}
    done

    # default to files if nothing returned and we're checking in.
    # otherwise, default to directories
    [[ address@hidden -eq 0 && $1 == ci ]] && _filedir || _filedir -d
} &&
complete -F _rcs ci co rlog rcs rcsdiff

# ex: ts=4 sw=4 et filetype=sh

OK - so that is the code that appears in my environment as BASH_FUNC__rcs - now 
the question is - why - and why does it persist? I am not aware of using 
completion with sudo or rcs - so where/why/how in bash do these /usr/share 
scripts get actioned?


reply via email to

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