My today's idea was to create a POSIX shell function to dump all given arguments, typical use would be to call it from a fucntion, where you already know some arguments are not well set (empty; not integer) and this way you can inspect all given arguments in one go. It reminds me of a PHP var_dump
function. :) Would anyone be able to find weak spots in there, all input is welcome.
#!/bin/sh
dump_arguments ()
# string function - prints arguments (position and content)
# indicates empty arguments and integer numbers
{
printf '%b' "dump_arguments()\\n----------------\\n$# arguments are being inspected"
[ $# -gt 0 ] && { printf ':\n'; i=1; } || printf '.\n'
while [ $# -gt 0 ]; do
printf '%s' "[$i]: '$1'"
[ -z "$1" ] && printf ' (empty)'
[ "$1" -eq "$1" ] 2> /dev/null && printf ' (integer)'
printf '\n'
shift 1
i=$((i+1))
done
} >&2
# inside some function you would call it like this
dump_arguments "$@"
# but to only try it out, you can call it directly
dump_arguments '1' '' 5