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

 

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