The basics of shell scripting

On the command line, we often work with a series of the same commands on a regular basis. It would be ideal to somehow bundle those commands and simplify the process, executing a single command or script to accomplish an overall objective that would take longer if we had to type out a single command repetitively. This is where shell scripting shines. We can place our commands, regardless of how long they may be, into a single file; give it an appropriate name; and execute the script as needed. The following code shows the basic syntax for creating a shell script:

#! /bin/sh

The preceding command is the first line in the script; it is used to define the shell interpreter. The first characters, #!, are often known ...

Get CompTIA Linux+ Certification Guide now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.