LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-27-2011, 12:53 PM   #1
Mirish326
LQ Newbie
 
Registered: Nov 2010
Posts: 6

Rep: Reputation: 0
New to linux


I would like know when it is necessary or advisable to write a shell script instead of shell function ?
 
Old 04-27-2011, 01:00 PM   #2
lisle2011
Member
 
Registered: Mar 2011
Location: Surrey B.C. Canada (Metro Vancouver)
Distribution: Slackware 2.6.33.4-smp
Posts: 183
Blog Entries: 1

Rep: Reputation: 25
Shell scripts

Are you using bash?

If so what is it that you mean?
 
0 members found this post helpful.
Old 04-27-2011, 02:33 PM   #3
alan_ri
Senior Member
 
Registered: Dec 2007
Location: Croatia
Distribution: Debian GNU/Linux
Posts: 1,733
Blog Entries: 5

Rep: Reputation: 127Reputation: 127
Quote:
Originally Posted by Mirish326 View Post
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.
 
1 members found this post helpful.
Old 04-27-2011, 04:33 PM   #4
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,396
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off




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

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration