Skip to content

Instantly share code, notes, and snippets.

@sethbergman
Forked from awwsmm/printargs.sh
Created June 23, 2019 07:42
Show Gist options
  • Select an option

  • Save sethbergman/1fb0e343dbc97c2213fdac6da00249c6 to your computer and use it in GitHub Desktop.

Select an option

Save sethbergman/1fb0e343dbc97c2213fdac6da00249c6 to your computer and use it in GitHub Desktop.
Easily print arguments passed to a `bash` script
#!/usr/bin/env bash
function printargs {
echo "arguments:"
ii=0
for arg; do
printf " %u: '%s'\n" "$ii" "$arg"
((ii++))
done
}
# usage:
#
# $ source ex.sh
# $ printargs a b c
# arguments:
# 0: 'a'
# 1: 'b'
# 2: 'c'
function another {
echo "printing arguments passed to 'another'..."
printargs "$@"
echo "...done."
}
# example:
# $ another "g h" 1
# printing arguments passed to 'another'...
# arguments:
# 0: ''
# 1: 'g h'
# 2: '1'
# ...done.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment