Scripts in ~/bin vs. functions in ~/.bashrc

Hi there,

Anyone knows what would be the cons and pros of adding a script in ~/bin vs. a function in ~/.bashrc?

I'm not sure how the system keeps tracks of some of the settings loaded in ~/.bashrc (like functions and aliases). Would I be right in thinking that this would all be loaded into memory and might slow down the system if I go "function" crazy? Should I add only small functions in ~/.bashrc and keep bigger scripts in ~/bin?

Just looking for some opinions, guidelines and best practices.

Thanks,

Vic.

Scripts take longer to execute (it requires forking and execing a new process), and they cannot change anything in your current environment unless you source them. Functions are run in the current shell.

Variables are local to the current shell unless they are exported.

In bash, functions may be exported so they are available to any commands you call.

Aliases are local to the current shell. I don't use them at all. As it says in the nash man page, "For almost every purpose, aliases are superseded by shell functions."

I have more than 100 functions loaded; I don't notice any slowdown.

Not necessarily.

Thank you very much for the detailed information Chris.

May I add that I was at last year's (2008) Ontario Linux fest and watched your presentation. It was very interesting!! :slight_smile:

Vic.