shell_dump_function
This is an old revision of the document!
Error loading plugin creole
Error: Class 'Doku_Handler_List' not found
More info is available in the error log.
Error: Class 'Doku_Handler_List' not found
More info is available in the error log.
To save piles of typing when debugging bash scripts, a dump() function that understands both regular and associative arrays:
is_array() { if [ -n "$BASH" ]; then declare -p ${1} 2> /dev/null | grep 'declare \-a' >/dev/null && return 0 fi return 1 } is_hash() { if [ -n "$BASH" ]; then declare -p ${1} 2> /dev/null | grep 'declare \-A' >/dev/null && return 0 fi return 1 } dump() { for var; do if is_array ${var} ; then echo ${var} = $(eval "echo "'${'"${var}"'[@]}') else echo ${var} = $(eval "echo \$${var}") fi done }
Then:
$ dump PATH HOME PATH = /home/rpjday/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/usr/local/go/bin:/home/rpjday/bin:/home/rpjday/go1.11.4/go/bin HOME = /home/rpjday
And arrays:
$ ARR=(fred barney wilma betty) $ dump ARR ARR = fred barney wilma betty $
shell_dump_function.1571954412.txt.gz · Last modified: 2019/10/24 22:00 by rpjday