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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access