Describe the purpose of shell scripts. Provide one example to reflect the use of variables, constructs, or functions.

Shell scripts are used to automate repetitive tasks and streamline system administration tasks in Unix-like operating systems. They are a collection of commands written in a scripting language (e.g., Bash) that can be executed directly by the shell.

One example of a shell script that reflects the use of variables, constructs, and functions is a script to backup a directory. Let's say we want to create a script that takes the path of the directory to be backed up, compresses it, and saves it in a specific location.

```bash
#!/bin/bash

# Take the directory path as an argument
directory_path=$1

# Create a timestamp to use in the backup file name
timestamp=$(date +"%Y%m%d%H%M%S")

# Define the backup directory
backup_dir="/path/to/backup"

# Create the backup filename
backup_filename="backup_${timestamp}.tar.gz"

# Create a function to perform the backup
backup_directory() {
# Check if the backup directory exists, if not, create it
if [ ! -d "$backup_dir" ]; then
mkdir -p "$backup_dir"
fi

# Compress the directory and save it in the backup directory
tar -czf "${backup_dir}/${backup_filename}" "$directory_path"
}

# Call the backup function
backup_directory
```

In this script, we define a variable (`directory_path`) to hold the path of the directory to be backed up. We also use the `date` command to generate a timestamp variable (`timestamp`) that will be used in the backup file name. The script defines the backup directory path and the backup filename using these variables.

A function (`backup_directory()`) is created to encapsulate the backup logic. Inside the function, we check if the backup directory exists and create it if needed. Then, we use the `tar` command to compress the directory specified by the `directory_path` variable and save it in the backup directory with the generated filename.

Finally, the script calls the `backup_directory` function to initiate the backup process.