#!/bin/bash read -p "Path to be added: " $path set -xv if [ "$path" = "/home/mike/bin" ]; then echo $path >> $PATH echo "new path: $PATH" else echo "did not modify PATH" fi set +xv
使用trap,EXIT模式仅检测退出时状态:
1 2 3 4 5 6 7 8 9 10 11 12 13
#!/bin/bash trap 'echo score is $score, status is $status' EXIT if [ -z $1 ]; then status="default" else status=$1 fi score=0 if [ ${USER} = 'superman' ]; then score=99 elif [ $# -gt 1 ]; then score=$2 fi
DEBUG模式可以检测每步状态:
1
trap 'echo "line ${LINENO}: score is $score"' DEBUG
GDB debug
使用友好的GDB debug会话:
1
gcc -ggdb test.c -o test.out
设置核心转储:
1 2 3 4 5
if ! grep -qi 'kernel.core_pattern' /etc/sysctl.conf; then sudo sh -c 'echo "kernel.core_pattern=core.%p.%u.%s.%e.%t" >> /etc/sysctl.conf' sudo sysctl -p fi ulimit -c unlimited # 使得当前会话解除核心文件大小限制