3 ms·
I think this would be more complete if the author also discussed variables. Then the justification for using functions versus external scripts becomes a little
by ksaj 7y ago
I think this would be more complete if the author also discussed variables. Then the justification for using functions versus external scripts becomes a little more clear.
I use functions for things that don't (or don't always / don't necessarily) need to do a disk read, and has something to do with the overall environment. For example, configuring directory and file colours depending on whether its a regular login or ssh. I choose what becomes a function by whether I think I can use it for more than one purpose. Ie: if it is reusable for something else. I grew up on Lisp, so it's a habit with plenty of advantages for my way of thinking of compute environments.
I use scripts for things that are more involved and don't get used often enough to justify living constantly in memory. Needless to say, my scripts assume nothing about what's in the .bashrc file unless I source them directly, so of course they could easily have their own variables and maybe even functions. And they are practical outside of the general shell environmental needs. For example, neofetch is the exact kind of thing I would script and never write as a standalone function in my bashrc. Some people might only want to see its output upon logging in. Others might happen to be curious at some given time, and run it just for the lolz. But neither justifies living in the shell's memory in between those occasions. So it stays as an external script.