< up >
2024-07-23

Bash argument - cheat sheet

variable description
$1 first argument
$2 second argument
$<n> <nth> argument
$@ all arguments as one string
$# count of arguments

example

#!/bin/bash

echo script started with $# args: $@

for arg in "$@"; do
    echo "$arg"
done
# $ ./script.sh --config=test --verbose 1 2
# script started with 4 args: --config=test --verbose 1 2
# --config=test
# --verbose
# 1
# 2