LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   New to linux (https://www.linuxquestions.org/questions/linux-newbie-8/new-to-linux-877430/)

Mirish326 04-27-2011 11:53 AM

New to linux
 
I would like know when it is necessary or advisable to write a shell script instead of shell function ?

lisle2011 04-27-2011 12:00 PM

Shell scripts
 
Are you using bash?

If so what is it that you mean?

alan_ri 04-27-2011 01:33 PM

Quote:

Originally Posted by Mirish326 (Post 4338251)
I would like know when it is necessary or advisable to write a shell script instead of shell function ?

Whenever you feel that is necessary or advisable to do so.

theNbomr 04-27-2011 03:33 PM

Strictly speaking, these are not distinct, since shell functions use the same scripting language as a script. Functions are handy when you want to re-use code, such as when you have a library of generic functions that you source in numerous other scripts. The system startup and configuration scripts for many distros use this technique.
Functions can be loaded and remain in the environment in your shell, ready for use when needed. I have a few of these that I load in my .bashrc file. One nice thing is that they are found by readline when I use the tab key for commandline completion.
--- rod.


All times are GMT -5. The time now is 10:01 PM.