From the course: Linux System Engineer: Bash Shell Scripting for Automation

Introduction to bash

From the course: Linux System Engineer: Bash Shell Scripting for Automation

Start my 1-month free trial

Introduction to bash

- [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.

Contents