測試腳本:
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