- sh -x 脚本名.sh
对整个脚本进行跟踪
[root@master shellexer]# cat bash.sh
#!/bin/bash
var=$1
echo $var
[root@master shellexer]# sh -x bash.sh hello
+ var=hello
+ echo hello
- hello #脚本输出结果
- #带+的表示被跟踪的代码
- set -x
对脚本内部部分代码进行跟踪,被跟踪的代码以set -x开始,与set +x结束
[root@master shellexer]# cat bash.sh
#!/bin/bash
var=$1
set -x
ceho $var
set +x
echo $var
[root@master shellexer]# sh bash.sh hello
+ ceho hello #带+的表示被跟踪的代码
bash.sh: line 4: ceho: command not found
+ set +x
hello
#脚本输出结果