Last active
February 13, 2021 13:27
-
-
Save ekussa/5f3720b796ba4bf34238c44430960313 to your computer and use it in GitHub Desktop.
How to place debug on bash
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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