Book Image

Linux Essentials - Second Edition

By : Christine Bresnahan, Richard Blum
Book Image

Linux Essentials - Second Edition

By: Christine Bresnahan, Richard Blum

Overview of this book

Linux Essentials, Second Edition provides a solid foundation of knowledge for anyone considering a career in information technology, for anyone new to the Linux operating system, and for anyone who is preparing to sit for the Linux Essentials Exam. Through this engaging resource, you can access key information in a learning-by-doing style. Hands-on tutorials and end-of-chapter exercises and review questions lead you in both learning and applying new information—information that will help you achieve your goals! With the experience provided in this compelling reference, you can sit down for the Linux Essentials Exam with confidence. An open-source operating system, Linux is a UNIX-based platform that is freely updated by developers. The nature of its development means that Linux is a low-cost and secure alternative to other operating systems, and is used in many different IT environments. Passing the Linux Essentials Exam prepares you to apply your knowledge regarding this operating system within the workforce.
Table of Contents (19 chapters)
17
EULA

Using Functions

A function is a part of a script that performs a specific subtask and that can be called by name from other parts of the script. Placing parentheses after the function name and enclosing the lines that make up the function within curly braces is how functions are defined:

myfn() {
   commands
}

The keyword function may optionally precede the function name. In either event, the function is called by name as if it were an ordinary internal or external command.

Functions are useful in helping to create modular scripts. For instance, if your script needs to perform half a dozen distinct computations, you can place each computation in a function and then call them all in sequence. Listing 11.6 demonstrates the use of functions in a simple program that copies a file but aborts with an error message if the target file already exists. This script accepts a target and a destination filename and must pass those filenames to the functions.