Bhash script - Mhoro Nyika Muenzaniso

Mune ino dzidziso, isu tinodzidza maitiro ekugadzira nekumhanyisa yakapusa Bhash script iyo inodhindira kunze 'Mhoro Nyika'.

Chii chinonzi Shebang (#!)

Yese Shell script inotanga ne Shebang #! zviratidzo. Izvi zvinotaurwa pamutsara wekutanga wechinyorwa uye zvinonyatso kuudza iyo Shell muturikiri achashandiswa kumhanyisa script.

#!/bin/bash ...

Mhoro Nyika Bhash script

Zvino, isu tichagadzira bash script iyo inodhindisa mazwi 'Halo Nyika' mune chinouraya.

Kutanga gadzira iyo faira inonzi hello_world.sh. Tichishandisa iyo terminal yatinonyora:

$ touch hello_world.sh

Yedu faira rave kugadzirwa.

Tevere, vhura iyo faira mune yako yaunofarira mupepeti; Ndiri kushandisa nano, saka zvingave:



$ nano hello_world.sh

Kamwe iyo hello_world.sh yakavhurika mupepeti wako, nyora mune inotevera mirairo:

#!/bin/bash echo 'Hello World'

Dzokorora Shell script

Iye zvino kudhinda iyo hello world, isu tinofanirwa kutevedzera script yeShell yatakagadzira.

Kune nzira dzinoverengeka dzekuita iyo script yeShell

$ sh ./hello_world.sh ## incorrect $ ./hello_world.sh ## correct $ bash ./hello_world.sh ## correct

Maitiro ekutanga haana kunaka, nekuti urikuudza Shell kuti ishandise muturikiri weShell kwete muturikiri webash.

Maitiro echipiri akarurama nekuti isu tinongomhanyisa script inozoshandisa muturikiri akatsanangurwa mufaira, mutsetse wekutanga mune script unova #!/bin/bash.

Maitiro echitatu akarurama zvakare nekuti mune iyi nyaya, tiri kuti tishandise muturikiri we bash iyo yakafanana neiyo inotsanangurwa mufaira.

Mvumo Inorambidzwa Paunenge Uchiita Shell script

Kana iwe ukaedza kumhanyisa yako script uchishandisa:

$ ./hello_world.sh -bash: ./hello_world.sh: Permission denied

iwe uchaona mvumo yakaramba kukanganisa. Izvi zvinodaro nekuti script haina mvumo yekuita.

Iwe unogona kupa iyo script kuita mvumo nekushandisa:

$ chmod +x ./hello_world.sh

Zvino, kana iwe uchimhanyisa iyo script zvakare, iwe uchaona iyo 'Hello World' yakadhindwa:

$ ./hello_world.sh Hello World