Bhash YeRupu uye Ipo Loop Mienzaniso

Kunge chero mumwe mutauro wekunyora, Bhash zvakare ine rutsigiro rwe zvishwe.

Zvishwe zvakanaka pakuita zvinodzokororwa mabasa. Isu tinokwanisa kushandisa zvishwe uye tichitora zvishwe muzvinyorwa zvedu zveBash.

Bhash YeRupu

Iyo syntax yeiyo chiuno ndeye:

for VARIABLE in PARAM1 PARAM2 PARAM3 do // scope of for loop done

Iyo for chiuno ichaita kune yega paramende. Iyo parameter inogona kuve manhamba, huwandu hwenhamba kana tambo, nezvimwe.

Bhash YeRoop Muenzaniso

Uyu muenzaniso wakapusa unodhindisa manhamba, 1 kusvika ku5 uchishandisa iyo chiuno:

#!/bin/bash for i in 1 2 3 4 5 do echo '$i' done

Kubuda:



1 2 3 4 5

Bhash YeRupu - Dhinda Range reNhamba

Isu tinogona zvakare kutsanangura huwandu hwenhamba kuti utsemuke kuburikidza:

Semuyenzaniso:

for i in {1..5} do echo '$i' done

Kubuda:

1 2 3 4 5

Bhash Loop Kupfuura Tambo

Isu tinokwanisa zvakare kushandisa iyo for loop kusunungura kuburikidza netambo parameter:

#!/bin/bash for day in MON TUE WED THU FRI SAT SUN do echo '$day' done

Kubuda:

MON TUE WED THU FRI SAT SUN

Bhash YeRupu - C Chimiro

Isu tinogona zvakare kushandisa C -style syntax kunyora iyo ye loop. Semuyenzaniso:

#!/bin/bash for ((i=1; i<=5; i++)) do echo '$i' done

Kubuda

1 2 3 4 5

YeLoop yekuPurinda Rondedzero yeFaira muRazvino Dhairekitori

Kunyora mafaera ese mune dhairekitori razvino uchishandisa iyo bash ye loop, isu tinoshandisa:

#!/bin/bash for fname in ./ do ls -l $fname done

Bhash Kunyange Iro Loop

Bhash zvakare inotsigira ichiruka. Ipo zvishwe zvichiita seti yemirairo kudzamara mamiriro aongorora kuva echokwadi.

Iyo syntax yeBash nepo chiuno chiri:

while [condition] do //execute instructions done

Mamiriro acho anoongororwa usati waita chero mirairo. Naizvozvo, zvinodikanwa kuve nenzira yekuvandudza mamiriro acho, zvikasadaro chiuno chinoita nekusingaperi.

Bhash Ipo Loop Muenzaniso

Iyi inotevera yakapusa nguva chiuno chinodhindisa manhamba 1 kusvika 5. Chiuno chinogumiswa kana nhamba iri huru kupfuura shanu.

#!/bin/bash num=1 while [ $num -le 5 ] do echo '$num' let num++ done

Bhash C-Chimiro Ipo Loop

Kufanana neiyo chiuno, isu tinogona zvakare kunyora iyo bash tichimbo loop mune C-maitiro senge mutauro.

Semuyenzaniso:

#!/bin/bash num=1 while((num <= 5)) do echo $num let num++ done