Shell komut dosyasında hata ayıklama sıkıcı bir iş olabilir. Bir kabuk komut dosyasında (shell script) hata ayıklama için çeşitli yollar vardır.
belli bir dizindeki dosyaların toplam boyutunu hesaplayan bir shell script yazalım.
1 |
[root@omeroner ~]# vim filesize.sh |
1 2 3 4 5 6 7 8 9 |
#!/bin/bash for filesize in $(ls -l . | grep "^-" | awk '{print $5}') do let totalsize=$totalsize+$filesize done echo "Gecerli dizinde toplam dosya boyutu: $totalsize" |
Bu çalıştırılabilir komut dosyasını debug modsuz çalıştırdığımızda çıktı aşağıdaki gibi olacaktır.
1 2 |
[root@omeroner ~]# ./filesize.sh Geçerli dizinde toplam dosya boyutu: 21716 |
Aynı scripti içinde hata ayıklama komutu ile yani debug mode ile çalıştırdığımızda;
Aşağıda görüldüğü gibi script içine set -xv ekledik.
1 2 3 4 5 6 7 8 9 10 11 12 13 |
[root@omeroner ~]# cat filesize.sh #!/bin/bash set -xv for filesize in $(ls -l . | grep "^-" | awk '{print $5}') do let totalsize=$totalsize+$filesize done echo "Gecerli dizinde toplam dosya boyutu: $totalsize" |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
[root@omeroner ~]# ./filesize.sh #!/bin/bash for filesize in $(ls -l . | grep "^-" | awk '{print $5}') do let totalsize=$totalsize+$filesize done ls -l . | grep "^-" | awk '{print $5}' ++ ls -l . ++ grep '^-' ++ awk '{print $5}' + for filesize in '$(ls -l . | grep "^-" | awk '\''{print $5}'\'')' + let totalsize=+873 + for filesize in '$(ls -l . | grep "^-" | awk '\''{print $5}'\'')' + let totalsize=873+173 + for filesize in '$(ls -l . | grep "^-" | awk '\''{print $5}'\'')' + let totalsize=1046+17511 + for filesize in '$(ls -l . | grep "^-" | awk '\''{print $5}'\'')' + let totalsize=18557+2721 + for filesize in '$(ls -l . | grep "^-" | awk '\''{print $5}'\'')' + let totalsize=21278+437 echo "Gecerli dizinde toplam dosya boyutu: $totalsize" + echo 'Gecerli dizinde toplam dosya boyutu: 21715' Gecerli dizinde toplam dosya boyutu: 21715 |
Hata ayıklama seçeneği ile Shell scriptti çalıştırabiliriz
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
[root@omeroner ~]# bash -xv filesize.sh #!/bin/bash for filesize in $(ls -l . | grep "^-" | awk '{print $5}') do let totalsize=$totalsize+$filesize done ls -l . | grep "^-" | awk '{print $5}' ++ ls -l . ++ grep '^-' ++ awk '{print $5}' + for filesize in '$(ls -l . | grep "^-" | awk '\''{print $5}'\'')' + let totalsize=+873 + for filesize in '$(ls -l . | grep "^-" | awk '\''{print $5}'\'')' + let totalsize=873+173 + for filesize in '$(ls -l . | grep "^-" | awk '\''{print $5}'\'')' + let totalsize=1046+17511 + for filesize in '$(ls -l . | grep "^-" | awk '\''{print $5}'\'')' + let totalsize=18557+2721 + for filesize in '$(ls -l . | grep "^-" | awk '\''{print $5}'\'')' + let totalsize=21278+437 echo "Gecerli dizinde toplam dosya boyutu: $totalsize" + echo 'Gecerli dizinde toplam dosya boyutu: 21715' Gecerli dizinde toplam dosya boyutu: 21715 |