GGistDev

Hello, World in Bash

Run commands interactively and write your first script.

Running a command

echo "Hello, world"
ls -la
pwd

Use man <cmd> or <cmd> --help for help.

First script

#!/usr/bin/env bash
set -euo pipefail

name=${1:-world}
echo "Hello, $name"

Save as hello.sh, make it executable, then run:

chmod +x hello.sh
./hello.sh Ada

Shebang and portability

  • Use #!/usr/bin/env bash to find bash via PATH
  • set -euo pipefail makes scripts fail fast on errors/undefined vars and pipeline failures

PATH and execution

  • Place scripts in a directory on PATH (e.g., ~/bin) or call with ./script.sh
  • Current directory is not on PATH by default

Summary

  • Run commands, write a script with a shebang, make it executable, and prefer strict mode