Shell Scripts are a great way to tackle a repetitive task. They are a convenient means for automating many different things. From mounting and dismounting volumes to manipulating and combining files. Shell scripts help make life easier.
In the video tutorial below, I walk through setting up a basic shell script, and discuss many of the steps necessary to create a very efficient and productive script.
Here are some key points from the video:
The use of Shell Scripts is ideal for tasks such as program execution, printing text, and file manipulation. Instead of typing the same thing into the command line over and over, shell scripts compile a series of shortcuts to help get the job at hand done.
- Variables and their uses
- There are four different ways to set a variable
- Single and double quotes do not act the same
- Your basic if statements
- Conditional Expressions
- Use built-in checks for existence of files, directories, executables, etc.
- && for AND, || for OR. Chain these together to simplify your scripts
- How to iterate over a list of items
- Redirecting 0, 1, and 2 in meaningful ways
- Output to File
- Using a single greater than symbol redirects standard out to a file, double to append
- Change Streams
- Can write standard error to standard out
- Send standard out from one program to the next
- Exit Codes
- Anything from 1-255 is an error
- Tells what is going to execute the body of the file