#!/usr/bin/env bash #------------------------------------------------------------------------------- # # print_args - easily inspect arguments passed to a bash script # # sources: # https://unix.stackexchange.com/a/332126/183920 # #------------------------------------------------------------------------------- function print_args { echo "arguments:" local ii=1 for arg; do printf " \$%u: '%s'\n" "$ii" "$arg" ((ii++)) done } # usage: # # $ print_args 3 "3.a" "hello world" # arguments: # $1: '3' # $2: '3.a' # $3: 'hello world' function example { echo "printing arguments passed to 'example'..." printargs "$@" echo "...done." printf "\$2 = %s\n" "$2" } # example: # # $ example "a b" 5.5 ho-ho # printing arguments passed to 'example'... # arguments: # $1: 'a b' # $2: '5.5' # $3: 'ho-ho' # ...done. # $2 = 5.5