---
title: Advanced BASH Exercises
description: In this post, we provide a set of exercises that should help you solidify
  your knowledge of BASH.  Note that these are NOT introductory level questions, and
  they assume that you are starting with a working knowledge of Linux and BASH.
author:
- J. David Giese
topics:
- Software
needs_pigments: true
---

BASH is the most widely-used and widely-supported shell for Linux.  There are other shells that are better than BASH in various ways, but we feel that none of these other shells are *better enough* to warrant replacing BASH as the de-facto standard when writing user shell scripts.  NetBSD and Debian use a stripped-down shell as the default for system scripts, which start with `#!/bin/sh`.  BASH is preferred for user scripts, which start with `#! /usr/bin/env bash`.  BASH is installed by default on almost all Unix-based operating systems, and the majority of the world's shell scripts are written in BASH.  For this reason, we suggest that all of our developers learn standard shell, starting with BASH.

BASH scripts are a domain-specific programming language that is well-suited to managing processes and files.  That being said, the large number of special characters appropriated for process management, its text expansions, and its unusual syntax make BASH poorly-suited for general purpose programming.  Accordingly, we think that BASH should only be used for scripts that are predominantly concerned with processes and files.

BASH is designed to be fast and convenient, and many commands must be typed frequently into the terminal.  Thus, the design goals for BASH scripts (being terse and convenient) clash with those for code written in a general-purpose language (being general and readable).  You can read some more discussion about this topic in our [article on programming languages](/articles/programming-languages/).  It is worth keeping these design constraints in mind when learning BASH and writing scripts.

 The questions focus on features of BASH that

- Commonly cause confusion
- Are very useful to know
- Are commonly encountered when reading or writing simple BASH scripts.

## Background reading

Before attempting to answer the questions, we recommend that you read the following resources:

- [Great introductory tutorial to BASH and shell scripting](http://linuxcommand.org/index.php)
- [The bash manual, the most comprehensive source](https://www.gnu.org/software/bash/manual/bashref.html)
- [Article about unofficial BASH strict mode](http://redsymbol.net/articles/unofficial-bash-strict-mode/)
- [Google shell style guide](https://google.github.io/styleguide/shell.xml)
- [About other shells](http://hyperpolyglot.org/unix-shells)
- [Sane bash defaults](https://github.com/mrzool/bash-sensible).

## Problems


