Every shell script has to target a particular shell and even keep shell versions in mind. As such, learn about the features of the bash shell, which is the default in Enterprise Linux.
- [Instructor] Bash is the default shell on Enterprise Linux, and as such, is the default vehicle for shell scripts. As of this recording, the version of Bash that comes with Enterprise Linux 7 is 4.2. Older versions of Linux may target an older version of Bash or even call the lowest common denominator, the bourne shell. Every shell script specifies the shell it wants to be executed with, although this can be overridden on the command line. Bash, as of version 4.2, has the following features: if then, else if conditionals, case statements, conditional tests for: file ownership, file permissions, numeric equivalence, text equivalence, file type as a file, file type as a directory, file type is a block device or character device, file is readable, writable or executable, a file exists, or a directory exists.
For loops, c-style for loops, while/until loops with conditions, brace expansion, arithmetic expansion, command substitution, integer math, mathematical conditions, indexed arrays, associative arrays, extended globs, and expanded regular expressions. Other features include functions, substring operations, parameter substitution, increment and decrement operators, bebug traps, positional arguments, subshells, and lastly co-processes.
Bash is good for automating tasks, and interacting with the operating system. There are jobs like running multiple processes asynchronously and waiting for all processes to finish before moving on and are very simple in Bash, but complex in other languages. There are times when you shouldn't use Bash, for instance, Bash does not handle complex data types like XML or JSON. Nor can it handle floating-point math internally, and relies on external commands for this. Bash, if written poorly, is difficult to trouble shoot as it's loosely typed and often runs code even if it doesn't work.
Also there's no object orientation in Bash.
Note: This course also helps you study to pass the Red Hat Certified Engineer (RHCE) exam—the benchmark certification for Red Hat Enterprise Linux.
- Basics of bash scripting
- Bash debugging
- Loading files in scripts
- Prompting for input
- Piping data into a script
- Outputting data from a script
- Controlling the flow of bash scripts with conditions
- Looping bash scripts
- Reviewing real-world examples