0

If I define a function in a bash script, e.g., envsetup.sh

function blabla() 
{
  echo "blabla"
}

then i source it by

. envsetup.sh

There is blabla function in my environment to use. However, if I remove this function and source it again, the blabla function is still there.

Why is it not deleted?

pepero
  • 7,095
  • 7
  • 41
  • 72

1 Answers1

1

It's still the same Bash process, and running your envsetup.sh simply amends that process. If you invoked a new Bash shell and ran your script there, then your function wouldn't exist.

You can remove that function in your shell script thought. You can do this via:

unset -f blabla
Brian Agnew
  • 268,207
  • 37
  • 334
  • 440
  • is it possible to add such command somewhere, so that everytime when I run envsetup.sh, I reset all the functions first, then add them again? – pepero Sep 16 '16 at 15:29
  • 2
    The best place would be in `envsetup.sh` itself, so that it can clean up functions that it may have defined previously. However, the long view says that `envsetup.sh` will primarily be executed once on a clean environment, not one in which it has gone through multiple edit/source cycles. – chepner Sep 16 '16 at 15:53