Tuesday, May 24, 2011

Good Tools for Debugging Bash Scripts

# builtin for displaying a list of all settable options
shopt

# to see if your process is in a login shell
shopt | grep login

# Print commands and their arguments as they are executed
set -x
# turns off printing of commands
set +x

# standard way to determine linux distribution
lsb_release -a

# current process id
$$

# display cmdline arguments to your script
cat /proc/$$/cmdline

# Not a tool, but something good to know
# $@ vs $*
## set ARGV
set a b c
## dollar star will expand to a single string
for x in "$*"; do echo $x; done
OUTPUT> a b c
## dollar at sign will expand to array of separate elements.
for x in "$@"; do echo $x; done
OUTPUT>
a
b
c

No comments: