Taula de continguts

debug en bash

https://www.cyberciti.biz/tips/debugging-shell-script.html

variables de entorno

código

podemos usar una función para hacer las llamadas a un modo DEBUG controlado todo desde una variable

#!/bin/bash
_DEBUG="on"
function DEBUG()
{
 [ "$_DEBUG" == "on" ] &&  $@
}
 
DEBUG echo 'Reading files'
for i in *
do
  grep 'something' $i > /dev/null
  [ $? -eq 0 ] && echo "Found in $i file"
done
DEBUG set -x
a=2
b=3
c=$(( $a + $b ))
DEBUG set +x
echo "$a + $b = $c"

herramientas