Pcornel
Linux · Shell & Bash

Bash

Cheat sheet · https://pcornel.dk/topic.php?topic=2681

Back to the Topic

Answer

Bash is the GNU Bourne-Again Shell, the default interactive shell on most distributions. It adds arrays, [[ ]] tests, brace expansion, history and better scripting to the POSIX sh language.

Remember

Start scripts with #!/usr/bin/env bash or #!/bin/bash and set -euo pipefail to stop on errors. Quote variables ("$x"). Check scripts with shellcheck.

First checks

  • bash -x script.sh — trace each expanded command
  • bash -n script.sh — syntax check only
  • shellcheck script.sh — common bugs and quoting problems
  • echo $? — exit code of the last command

Commands

bash --version
Read current Shell & Automation state for a bounded verification step.

Verify in this order

script starts with the Bash shebang → parsed → each line expanded → commands run → exit code returned

Where it usually breaks

First mismatch in persistent intent → provider/parser/generator → kernel/userspace runtime → dependency/security context → logs/counters → consumer-visible read-back; preserve identity/native diagnostic/pre-state before mutation.

Read-only verification commands unless stated otherwise. Confirm syntax for your platform and release. Full reference: https://pcornel.dk/topic.php?topic=2681

Confirmation

Confirm action

Continue?