In this lesson, we will explore the potential of Bash scripting. Since we can run any terminal command in a Bash script, there are truly endless possibilities. The ability to execute and link multiple commands with programming logic allows us to easily automate tasks and run configuration services.
Bash scripts are often the backbone of many services and servers! In the industry, scripts are commonly used for:
- Application installation or deployment. A script can contain instructions to compile, configure, and execute an application. Packages downloaded via the terminal with
curlare often installed and configured to the environment using scripts.
- Automating tasks during a cron job, which essentially schedules scripts to run. For example, a cron job might trigger a script to periodically check the health of a web API and set off an alert if the service is unreachable.
Scripts are great tools that can also be referred to by other scripts! That means we can reuse scripts others write on the internet.
In this lesson, we will practice writing two scripts:
- One that prints a file directory structure in a tree-like format.
- One that prints song lyrics and has the user guess the song name.
As a preview, let’s run the scripts we will be writing.
./tree.sh ~ on the terminal. This script prints the directory structure of the current directory.
./lyrics.sh -a Adele -s Rolling in the Deep in terminal.
This script fetches the lyrics of the requested song. We will be using this script to develop our game in a later exercise.