Kolam Ayer MakersLinux Foundations

Script Arguments

Core Idea

Arguments let one script handle different inputs.

Inside a shell script:

Practice Alone

Create a scratch script:

mkdir -p ~/scripts
micro ~/scripts/args.sh
#!/bin/bash
set -euo pipefail

printf 'count=%s\n' "$#"
printf 'first=%s\n' "${1:-missing}"

Run it with different inputs:

bash ~/scripts/args.sh
bash ~/scripts/args.sh makers
bash ~/scripts/args.sh "two words"

Watch Out

Done When

You can write a script that behaves differently based on its arguments.

Docs Pointers