Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
snipplets:prargs [2010/07/31 09:06]
127.0.0.1 external edit
snipplets:prargs [2013/03/23 16:25] (current)
ormaaj
Line 3: Line 3:
 ---- dataentry snipplet ---- ---- dataentry snipplet ----
 snipplet_tags:​ debug, arguments snipplet_tags:​ debug, arguments
-LastUpdate_dt: ​2010-07-31¬†+LastUpdate_dt: ​2013-03-23¬†
-Contributors:​ Snappy (IRC)+Contributors:​ Snappy (IRC), Dan Douglas¬†
 +type: snipplet
 ---- ----
  
Line 16: Line 17:
 It uses the [[commands:​builtin:​printf | printf command]] to generate a list of arguments, even with escape sequences interpreted. This list is shown formatted by the nl(1) utility. It uses the [[commands:​builtin:​printf | printf command]] to generate a list of arguments, even with escape sequences interpreted. This list is shown formatted by the nl(1) utility.
  
 +Another alternative with colorized output. If run in Bash, it temporarily disables all debug output for itself, including the test that determines whether to hide debug output. In ksh, tracing would have to be enabled on the function to show debug output, so it works out to being equivalent.
 +
 +<code bash>
 +# Bash or ksh93 debugging function for colored display of argv.
 +# Optionally set OFD to the desired output file descriptor.
 +function args {
 + { BASH_XTRACEFD=3 command eval ${BASH_VERSION+"​$(</​dev/​fd/​0)"​};​ } <<​-'​EOF'​ 3>/​dev/​null
 + case $- in *x*)
 + set +x
 + trap 'trap RETURN; set -x' RETURN
 + esac
 +EOF
 +
 + [[ ${OFD-1} == +([0-9]) ]] || return
 +
 + if [[ -t ${OFD:-2} ]]; then
 + typeset -A clr=([green]=$(tput setaf 2) [sgr0]=$(tput sgr0))
 + else
 + typeset clr
 + fi
 +
 + if ! ${1+false}; then
 + printf -- "​${clr[green]}<​${clr[sgr0]}%s${clr[green]}>​${clr[sgr0]} " "​$@"​
 + echo
 + else
 + echo 'no args.'
 + fi >&"​${OFD:​-2}"​
 +}
 +</​code>​
  • snipplets/prargs.1280567177.txt
  • Last modified: 2011/06/24 05:10
  • (external edit)