shell脚本简单调试

测试脚本:

1 #!/bin/bash
2 
3 touch /home/test.txt
4 
5 ls /home
6 
7 hostname
8 
9 pwd

运行结果:

[root@localhost ~]# ./xxx.sh 
test.txt
localhost.localdomain
/root

脚本调试方法:

修改脚本:

#!/bin/bash

touch /home/test.txt

ls /home

if   // 语法错误

hostname

pwd

检测脚本语法错误: bash -n

[root@localhost ~]# bash -n ./xxx.sh

结果:

[root@localhost ~]# ./xxx.sh 
test.txt
./xxx.sh: line 12: syntax error: unexpected end of file

脚本调试:bash -x 

[root@localhost ~]# bash -x xxx.sh 

结果:

[root@localhost ~]# bash -x xxx.sh 
+ touch /home/test.txt
+ ls /home
test.txt
xxx.sh: line 12: syntax error: unexpected end of file

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章