Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
<strong>Bash</strong> <strong>Guide</strong> for <strong>Beginners</strong><br />
command > file 2>&1<br />
11.3. Summary<br />
Functions provide an easy way of grouping commands that you need to execute repetitively. When a function<br />
is running, the positional parameters are changed to those of the function. When it stops, they are reset to<br />
those of the calling program. Functions are like mini-scripts, and just like a script, they generate exit or return<br />
codes.<br />
While this was a short chapter, it contains important knowledge needed for achieving the ultimate state of<br />
laziness that is the typical goal of any system administrator.<br />
11.4. Exercises<br />
Here are some useful things you can do using functions:<br />
1.<br />
Add a function to your ~/.bashrc config file that automates the printing of man pages. The result<br />
should be that you type something like printman , upon which the first appropriate man<br />
page rolls out of your printer. Check using a pseudo printer device for testing purposes.<br />
As an extra, build in a possibility for the user to supply the section number of the man page he or she<br />
wants to print.<br />
2. Create a subdirectory in your home directory in which you can store function definitions. Put a couple<br />
of functions in that directory. Useful functions might be, amongs others, that you have the same<br />
commands as on DOS or a commercial UNIX when working with Linux, or vice versa. These<br />
functions should then be imported in your shell environment when ~/.bashrc is read.<br />
Chapter 11. Functions 136