Skip to content

Instantly share code, notes, and snippets.

@ekussa
Last active February 13, 2021 13:27
Show Gist options
  • Save ekussa/5f3720b796ba4bf34238c44430960313 to your computer and use it in GitHub Desktop.
Save ekussa/5f3720b796ba4bf34238c44430960313 to your computer and use it in GitHub Desktop.
How to place debug on bash
#!/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"
a=4
b=5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment