O'Reilly logo

Practical Linux by Bill Ball, John Ray, Michael Turner, M. Drew Streib

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Writing Shell Functions

Shell functions are one of the more advanced features of the bash shell programming language. In most programming languages, programmers accumulate snippets of code that are useful in more than one program. To make the reuse of code easier between programs, these snippets of code are grouped into functions. They are essentially subprograms that your shell programs can call. BASIC calls these subroutines; Pascal and Modula-2 call them procedures; and C, C++, and bash call them functions.

Functions usually take an argument or more to pass to them the data they are supposed to work on. The idea is that the code in a function should be packaged in such a way as to make it useful in more than one circumstance. To allow more ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required