How can I create a local function in my bashrc?

Use unset as last line in your .bashrc:

unset -f do_stuff

will delete/unset the function do_stuff.

To delete/unset the variables invoke it as follows:

unset variablename

The other option is to use underscores like in other scripted languages to indicate you do not intend for this function to be public. The likelihood of you typing _do_foo is pretty small and also unlikely to conflict with anyone else.


Only solution I can think of is underscore it and give it a pretty unique name, maybe even namespacing it with dots like a fancypants language (but this will not work in ye olde sh).

Heck, this won't have any conflicts:

_my_foobar_method_91a3b52d990f4a9f9d5d9423ec37b64c () {
    # Custom proprietary logic protected ID 10 T intellectual property copyright clauses.
    cat <<< `echo $(xargs printf <<< "$1")`; }
}

Tags:

Bash

Bashrc