Shiryawa a cikin bash - kashi na 2

Kashi na biyu wannan karamin koyawa shirye-shirye a cikin Bash, inda muka koya amfani hawan keke da sauran kayan aikin da zasu taimaka mana inganta ayyukan mu rubutun.

Idan Idan akwai sharadi

Aikin If shine sanya tata da aiwatar da aiki ko aiki ga kowane nau'in tacewar da aka yi amfani da shi. Tsarinsa kamar haka:

Idan [sharadi]; sannan elif yayi umarni [sharadi]; sannan kuma yayi umarni; fi umarni

Misali ya nuna kusa da Ga madauki a cikin sashensa.

Ciclos

1. Duk da yake: zai aiwatar da duk umarnin da aka kayyade tsakanin aikatawa da aikatawa muddin yanayin gaskiya ne. Idan muna son wucewa ga masu sarrafa kwatancen zuwa gare shi, bayanin dole ne ya kasance a cikin baka.

yayin da CONDITION / COMMAND suke yin umarni

Misali: tebur na yawan lambobi

#! / bin / bash X = 1 amsa kuwwa "Shigar da lamba ka latsa ENTER" karanta M # Ikon madauki wanda X bai kai ko yayi daidai da 10 ba yayin da [$ X –le 10] suke yin # IN R muna adana ninkin na X ta MR = $ [X * M] # An buga wannan narkarwar akan allon amsa kuwwa "$ M * $ X = $ R" # Tare da bari, za mu kara darajar X da raka'a 1 bari X = $ X + 1 gama

2. Don: adana jerin abubuwan abubuwa a cikin canji, wanda za'a yi amfani dashi don aiwatar da wasu ayyuka tare da kowane zagaye.

don KYAUTA a cikin ELEMENTS yayi umarni da anyi

Misali: shirin da yake kwafin fayil daga babban fayil zuwa wancan, yana maye gurbin tsohon fayil.

# / bin / bash #Muna kafa tushen da kuma inda za a tura kundin adireshi ORIGIN = / home / user / Downloads DESTINATION = / home / user / Documents # Mun sanya kanmu a cikin asalin cd $ ORIGIN #Daga dukkan fayilolin, kawai muna son wanda shine # kira FILE don FILE a cikin * yi ARCH-DESTINATION = "$ DESTINATION / $ FILE" # -f yana tace mana fayiloli na yau da kullun, tunda kundayen adireshi basa # mana kyau. –Nt bata tace # fayiloli "sabbi" sama da wadanda # aka samu a jakar makoma idan [-f $ FILE] && [$ FILE –nt $ ARCH-DESTINATION]; sai kuma amo "Kwafin $ FILE ..." # mun kwafe fayil din tare da cp cp $ FILE $ ARCH-DESTINATION fi anyi #We cd don fita daga babban fayil din cd

Wani misali: rubutun inda mai amfani dole ne yayi hasashen lambar bazuwar da komputa ya samar.

# / bin / bash #An samar da lamba bazuwar daga 1 zuwa 10, an # adana a RANDOM RANDOM = $ [$ RANDOM% 10 + 1] yayin da [1] yayi kuwwa –n "Shigar da lamba:" karanta NUM # Kwatanta idan lambar da mai amfani ya zaba ta dace da RANDOM; tuna amfani da $ don kimanta #values ​​na masu canji kuma ba sunayen su ba idan [“$ NUM –eq“ $ RANDOM ”]; sai amsa kuwwa "Kun samu daidai!" # warwarewa yana ba da damar kawo karshen madauki yayin karyewa #Idan lambar ta kasa RANDOM elif "" sa'an nan kuma amsa kuwwa "Yana da ƙasa" "Idan ba haka ba, shi ne mafi girma daga RANDOM kuma amsa kuwwa" IT IS mafi girma "fi yi

3. Har zuwa: kwatankwacin tsari cikin Tsarin Duk da yake, sai dai lambar koyaushe tana aiwatarwa yayin kimanta yanayin ba daidai bane, ma'ana, shirin yana ci gaba da aiwatarwa "har sai yanayin ya faru"

har sai CONDITION / COMMAND yayi umarni anyi

Misali: buga lambobi 10-20 cikin tsari

#! / bin / bash CONT = 20 #Amma dai idan lissafin bai kai 10 ba (-lt, “ƙananan #than”) ana aiwatar da lambar har sai [$ CONT -lt 10]; yi amsa kuwwa "COUNTER $ CONT" #A CONT an cire ta daga ƙungiya bari CONT- = 1 yayi

4. Zaɓi: wannan zagayen ƙarshe lamari ne na musamman, tunda ana amfani dashi gaba ɗaya don yin menus da sauri. Yana aiki kwatankwacin Ga madauki.

zaɓi VARIABLE a cikin LIST na dokokin da aka yi

Misali: bawa mai amfani da ikon ci gaba ko ƙare rubutun.

#! / bin / bash #item mai canzawa ne wanda yake amsar abin da # mai amfani ya zaba, Ci gaba da isharshe su ne zaɓin da yake da shi, kodayake za a iya ƙara wasu zaɓuɓɓuka # ƙarin zaɓin abu a Ci gaba isharshe yi #Idan mai amfani ya zaɓa ƙare shirin, sannan tare da hutu zamu fita daga sake zagayowar. idan [$ abu = "Gama"]; to karya fi yi
Na gode Juan Carlos Ortiz!

Abubuwan da ke cikin labarin suna bin ka'idodinmu na ka'idojin edita. Don yin rahoton kuskure danna a nan.

13 comments, bar naka

Bar tsokaci

Your email address ba za a buga. Bukata filayen suna alama da *

*

*

  1. Mai alhakin bayanan: Miguel Ángel Gatón
  2. Dalilin bayanan: Gudanar da SPAM, gudanar da sharhi.
  3. Halacci: Yarda da yarda
  4. Sadarwar bayanan: Ba za a sanar da wasu bayanan ga wasu kamfanoni ba sai ta hanyar wajibcin doka.
  5. Ajiye bayanai: Bayanin yanar gizo wanda Occentus Networks (EU) suka dauki nauyi
  6. Hakkoki: A kowane lokaci zaka iyakance, dawo da share bayanan ka.

  1.   Matsakaici Matsakaici m

    Ina tsammanin wani abu kamar haka: tar -cf - Directory | (cd / sauran / shugabanci; tar -xvf -)

    To zai yi kama da / wani / shugabanci / Littafin Adireshi
    A wannan hanyar na matse Directory kuma sai ku rarrabu dashi a wani waje….

  2.   Miguel Mala'ika m

    Barka dai, mai koyarwa mai kyau, Ina koyo game da batun kuma komai yayi daidai, kawai ban sami damar yin shirin da zai taimake ni ba, don ganin ko zaku iya taimaka min don Allah.

    Ina buƙatar yin sake zagayowar, wanda zai karɓa azaman sigogi jerin fayil ɗin tushe, wannan jerin kawai yana kawo sunaye (ba tare da haɓakawa ba), don haka sake zagayowar yana yin mai biyowa, bincika sunan da aka karɓa a cikin shugabanci (wanda shine wanda za mu nema), cirewa da kwafe fayil ɗin (cikakken suna tuni tare da tsawo) da kuma cikakkiyar hanya kuma ƙirƙirar ta a cikin wani fayil ɗin makoma

    Ya zuwa yanzu ina da masu zuwa:

    yayin karanta layi
    do
    amsa kuwwa -e "$ layi"
    nemo / gida / myuser / dof "$ line" -exec readlink -f {};
    yi <testlist.txt Zuwa yanzu na karanta fayil din, duk layin da yake da shi, amma ba zan iya sanya shi ya nemi wannan file din ba in ciro bayanan, idan zaka iya taimaka min don Allah, na gode. Murna

  3.   Pamela galaviz m

    Na gode sosai da gudummawar 🙂

  4.   Mario Xavier m

    hi ... Ina fatan zaku iya taimakawa a aiki na gaba ... Fitar da fayil din a cikin tgz a cikin takamaiman kundin adireshi, ban da tantance mai amfani da rukuni na dukkan kundin adireshi da fayilolin da ke akwai, da sanya izini ga fayiloli da kundin adireshi
    lura: fayilolin shirye don karatu da rubutu
    kundin adireshi izini

  5.   johnk m

    ARCH-DESTINATION abu ne mai canzawa wanda muke son adana hanyar fayil ɗin da aka nufa, a yafe rashi. Bayan haka, ga wannan mai canzawar muna nuna canjin KADDARA, wanda ke sama yana dauke da hanyar zuwa babban fayil ɗin Takardun kuma mun ƙara "canji" FILE, wanda ya ƙunshi sunan fayil ɗin. Idan wannan fayil ɗin, misali, list.doc ne, mai canzawa ARCH-DESTINATION zai yi daidai da /home/Usuario/Documentos/listado.doc

  6.   Bari muyi amfani da Linux m

    Labari ne da ya gabata. Kuna iya samun damar ta a http://usemoslinux.blogspot.com

    Rungume! Bulus.

  7.   Frank m

    Abokina sannu da zuwa abokina kawai na gode, shafinka yana da kyau, amma ba zan iya samun ɓangaren farko na Programming a Bash ba, inda na samu shi godiya, gaisuwa

  8.   Saito Mordraw m

    Bangarori biyu na ban mamaki, ina taya ku murna.

    Kawai ban mamaki.

  9.   Fredy m

    da

  10.   Hugo m

    Barka dai, Ina yin shiri ne da CASE, abin da nakeso yayi kuma ban san yadda ba, misali:

    amsa kuwwa Picks wani zaɓi:
    Kira
    amsa kuwwa 1. zaɓi 1
    amsa kuwwa 2. zaɓi 2
    amsa kuwwa 3. zaɓi 3
    amsa kuwwa 4. zaɓi 4
    amsa kuwwa 5. Fita
    karanta var
    harka "$ var" a
    1)
    amsa kuwwa "Ka zabi 1"
    ;;
    2)
    amsa kuwwa "Ka zabi 2"
    ;;
    3)
    jefa "… .."
    ;;
    4)
    jefa "…."
    ;;
    5)
    jefa "…"

    ;;
    *)
    amsa kuwwa "ba daidai ba zaɓi"
    ;;
    cewa C

    to abin da ban san yadda zan yi ba shine lokacin da na zabi zaɓi 4 wanda shine barin, tambaya idan da gaske ina son barin, kuma ku ba ni zaɓi 2 Y & N

    dayan kuwa shine lokacinda ka zabi wani abu banda lambobi 1..5 kar ka zabe ni daga rubutun….

    Za a iya taimaka mani godiya.

  11.   DAPAMA21 m

    Barka dai, na fara rubutun ne wata 1 da ya gabata kuma albarkacin rubutunka. Zan yi kusan 15-20. Na gode sosai a gaba. Amma yanzu malaminmu ya ba mu aikin da na kasance cikin ƙarancin aiki. Tunda malamin yayi tambaya:
    wuce kundin adireshi, kwafa zuwa gidanka duk fayilolin da suke cikin wannan kundin haruffa tare da sanya musu fayil1 file2 da sauransu ... da sauransu ...
    Yanzu ina lokacin nemo ko gano wuri, ina so nayi amfani da Find amma lokacin da nake bashi lambar kuskure kamar yadda na sanya ta ta hanyar ɓata, izinin da aka ƙi sai na sami kuskure kuma sanya wurin da nake nan:
    gano wuri $ 1 | gaishe "/ $ {1} \ $"
    amma tabbas da wannan duk suka fito ...
    Na gode sosai idan kun karanta shi.
    Idan za ku iya taimaka min zai zama alheri.

  12.   Luis m

    Ina son ku taimaka min da wannan.
    1.-Shigar da adadi mai yawa akan maballin sannan ka nuna sau biyu kuma ninki uku akan allon. 2. - Yi shiri don yanke shawara idan lambar da aka shigar ta mabuɗin keyboard za'a iya raba ta 3 ko a'a.
    3.- Yi shiri don nemo adadin: ???????? + ???????? + ???????? + ???????? + ⋯? ???????
    4.- Yi shiri don nemo adadin 1 + 3 + 5 + 7 + 9 · · · + + (2n + 1).
    5.-Yi shiri wanda zai buga kalmar Linux a allo sau 10
    6.-Yi shirin da yake buga kalmar Linux akan allon adadin lokutan da mai amfani ya nuna.
    7.-Shigar da adadi cikin awanni ka maida su mintuna da dakika.
    8.-Lissafa yankin alwatika
    9.-Shigar da lamba a jikin maballan, to idan ka shigar da 2 ya zama murabba'i, 3 cubed, 4 zuwa na huɗu da sauransu har zuwa 6.
    10-Lissafin fansho wanda ɗalibi zai biya, dole ne a shigar da lambar sana'a, da ranakun biya.
    CODE
    MUSAMMAN
    LOKACI
    LOKACIN RANA
    1
    GASKIYA
    160
    1
    2
    NONO
    150
    1.5
    3
    SAKATARE
    140
    2
    4
    Tourism
    180
    2.5
    5
    LISSAFI
    160
    1
    Dole ne ku nuna ƙwarewar da kuke karantawa, farashin fansho, tsoho da jimillar kuɗin da za a biya.

  13.   charly m

    Barka dai, wani zai taimake ni?
    Ina bukatan «Nemi kalmomi uku ta madannin rubutu sannan ku nuna su cikin tsari na baƙaƙe daga A zuwa z»
    A cikin Bash ko sh yare don LINUX porfaborrrr