Ukuhlela ku-bash - ingxenye 1

Ngenkathi siyisebenzisela imisebenzi yokuphatha noma yokuphatha ifayili, i ukududuza de Linux inweba ukusebenza kwayo kudlula leyo njongo, kusivumela ukuthi sihlele izikripthi Lo mhlahlandlela awenzelwe ukuthi ube yinkomba ephelele yohlelo lweBash, kepha kunalokho ukwethulwa kwemiyalo nezakhiwo eziyisisekelo, ezizosivumela ukuthi sandise amandla ohlelo lwethu lwe-GNU / Linux.

Yini i- "Script"?

Ngokuyisisekelo sithi yifayela eliqukethe ikhodi ebhalwe ngolimi oluthile lohlelo olusetshenziswa uhlelo ukwenza umsebenzi othile. Akudingi ukuba nokufaka kwangaphandle noma isikhombimsebenzisi sokuqhafaza, kepha kuyadingeka ukuthi kubangele idatha esetshenzwe ukuthi ikhishwe (noma ngabe umsebenzisi akaboni).

Ulimi olusetshenziswa nguBash luchazwa ngumtoliki walo futhi luhlanganisa i-syntax yamanye amaShell, njengeKorn Shell (ksh) noma iC Shell (csh). Imiyalo eminingi evame ukusetshenziselwa ikhonsoli nayo ingasetshenziswa kwizikripthi, ngaphandle kwalezo eziphathelene nokusatshalaliswa okuthile.

Ukwakheka kweSkripthi

Ukuqala kumele sibe nesihleli sombhalo futhi sifise ukuluhlela. Amafayela esiwagcina nge-.sh extension angenziwa (noma ahunyushwe) yikhonsoli, inqobo nje uma umugqa wokuqala ungokulandelayo:

#! / bin / bash

Lokhu kutshela uhlelo ukuthi lusebenzise ikhonsoli ukuqhuba ifayili. Ngaphezu kwalokho, umlingiswa # ukuvumela ukuthi ubhale imibono. Ukwenza isibonelo esilula sengeza umugqa owodwa, obonwe esithombeni esilandelayo:

Umyalo we-echo ukhombisa umlayezo esikrinini, kulokhu okujwayelekile "Sawubona mhlaba!" Uma siyigcina futhi siyisebenzisa ngekhonsoli sizobona umphumela.

Imiyalo Eyisisekelo

Imiyalo elandelayo ijwayelekile futhi ilusizo kakhulu kunoma yiluphi uhlobo lohlelo. Siyacacisa ukuthi kunezinye eziningi, kepha okwamanje sizokhuluma ngokulandelayo.

Ama-aliases: ivumela uchungechunge lwamagama ukuthi lushintshwe olufushane, okuvumela ukunciphisa ikhodi.

# dala i-alias ebizwe ngekheli le- # Downloads ifolda alias per = '/ home / user / Downloads' #Sonke isikhathi lapho sifuna ukusisebenzisa kufanele sivele sibize # igama elisha nge #Ukuchitha lawo ma-alias, thina sebenzisa ama-ulias alias per

break: ikuvumela ukuthi uphume ngokushesha kwe- for, ngenkathi, kuze kube noma ukhethe i-loop (sizofunda ngokuningiliziwe ngokuhamba kwesikhathi)

#Dala iluphu elizokwabela izinombolo kusuka ku-1 kuye ku-5 # 'ekuphendukeni kwe-loop' ngakunye kwe-counter ku-1 2 3 4 5 yenza #Siphrinta inani lamanje le-#counter eguqukayo, ehlaziywa ngumlingiswa $ bhala "$ counter" #Uma inani lekhawuntari lilingana no-3 uma [$ counter –eq 3] bese # Ikhefu liphuma ku-loop yekhefu

continue - Okufana nekhefu, ngaphandle kokuthi ayinaki i-loop yamanje bese iya kolandelayo.

#Dala iluphu elizokwabela izinombolo kusuka ku-1 kuye ku-5 #kunye nenye "i-loop ye-loop" yekhawunta ku-1 2 3 4 5 yenza # Uma inani le-counter lilingana no-3 uma [$ counter –eq 3] bese # Qhubeka uvimbela wonke umjikelezo wamanje ekuhlaziyweni ngokugxumela emzuliswaneni olandelayo, okungukuthi, # inani le-3 ngeke liphrintwe. qhubeka i-fi echo "$ counter" yenziwe

memezela: umemezela okuguquguqukayo futhi ubanikeze amanani, njenge-typeset (isebenza ngendlela efanayo). Singayihlanganisa nezinye izinketho: -i Imemezela amanani aphelele; -r kokuguquguqukayo kokufunda kuphela, inani lalo elingenakuguqulwa; –A yama-arrays noma i- “arrays”; -f yemisebenzi; -x Ngokuguquguqukayo "okungathunyelwa" ngaphandle kwendawo yombhalo uqobo.

memezela -i-nombolo = i-12 yazisa -x pi = 3.14

usizo: kukhombisa usizo lomyalo othize.

imisebenzi: ikhombisa izinqubo ezisebenzayo.

#With –c sikhombisa igama lemiyalo, nge-p # the pid (process id) yenqubo ngayinye. imisebenzi -cp

ake: hlola isisho sezibalo

let a = 11 let a = a + 5 # Ekugcineni siphrinta inani lalo eli-16 echo "11 + 5 = $ a"

local: dala okuguquguqukayo kwasendaweni, okufanele kusetshenziswe ngokunconywayo emisebenzini yeskripthi uqobo ukugwema amaphutha. Ungasebenzisa imisebenzi efanayo nomyalo wokumemezela.

i-v1 yasendaweni = "Lokhu ukwahluka kwasendaweni"

ukuphuma: kuvumela ukuphuma ku-Shell ngokuphelele; iwusizo ezimeni lapho sisebenza khona ngewindi leShell elingaphezu kwelilodwa, lapho umyalo wokuphuma uzovumela kuphela iwindi elilodwa ukunqanyulwa ngasikhathi.

phrinta: ikuvumela ukuthi uphrinte idatha bese uyifometha. Inezinketho eziningi, ngakho-ke sizokhuluma ngezimbalwa.

#% f iphrinta njengenombolo entantayo, n ye- new # line printf "% fn" 5 5.000000 # & d ivumela ukwedlula izinombolo zamadesimali njengama-agumenti printf "Kunama-oda e-% d anenani elingu-% d dollars.n" 20 500 Kukhona Ama-oda angama-20 anenani lamaDola angama-500.

funda: funda umugqa kusuka kokufakwayo okujwayelekile (imodyuli esetshenziselwa ukulayisha idatha ngekhibhodi ngokwesibonelo). Singadlula izinketho ezinjengalezi: -t Ukunikeza isikhathi somkhawulo wokufunda; -a Ukuze igama ngalinye linikezwe isikhundla ku-aname array; -d ukusebenzisa i-delimiter ezobhalwa ekugcineni komugqa; phakathi kwabanye.

echo "Faka igama lakho bese ucindezela ENTER" #Funda igama eliguqukayo funda igama echo "Igama lakho ngu $ name"

uhlobo: luchaza umyalo nokuziphatha kwawo. Kungaba wusizo ukuthola izincazelo zedatha yomyalo ngamunye.

uhlobo –a '[' #type lusitshela ukuthi [umyalo weShell builtin [uyiShell builtin # -a ikuvumela ukuthi uthole izinkomba eziqukethe i- # enokusetshenziswa enegama elibhaliwe. [ngu / usr / bin / [

ulimit: kukhawulela ukufinyelela nokusetshenziswa kwezinsizakusebenza ezithile zohlelo kuzinqubo, ezilungele izinhlelo ezivumela izinguquko zokuphatha noma eziqondiswe ezinhlotsheni ezahlukahlukene zabasebenzisi. Lapho sibeka umkhawulo sibhala inombolo emele ama-kilobytes womkhawulo.

#Sibona imikhawulo yethu yamanje i-ulimit -a # -f ivumela ukukhawulela abasebenzisi ukuthi bangakwazi # ukudala amafayela amakhulu kuno-512000 Kb (500 #Mb) ulimit -f 512000 # -v anciphisa inkumbulo ebonakalayo yenqubo. ulimit –v 512000

linda: linda inqubo ethile noma umsebenzi ozokwenziwa ukuze uqhubeke.

#Isikripthi silinde ukuthi kwenziwe inqubo ye-pid # 2585

linda 2585

Eminye imiyalo ewusizo esingayengeza kumaskripthi imelwe yizimpawu.

!!: sebenzisa umyalo wokugcina futhi

i-wer: yenza umyalo wokugcina oqale ngegama elithi "wer".

'==', '! =', '>', '<', '> =', kanye '<=': opharetha bezobudlelwano.

|: U-opharetha we-OR uvame ukusetshenziselwa ukujoyina izinkulumo ezimbili ezijwayelekile.

Ukuphunyuka komyalo okuvumela ukuthi ufomethe izinkulumo. Isibonelo: a for a sound alert, n for newline, b for backspace, njll.

Ngiyabonga uJuan Carlos Ortiz!

Okuqukethwe yi-athikili kunamathela ezimisweni zethu ze izimiso zokuhlelela. Ukubika iphutha chofoza lapha.

Amazwana ayi-10, shiya okwakho

Shiya umbono wakho

Ikheli lakho le ngeke ishicilelwe. Ezidingekayo ibhalwe nge *

*

*

  1. Ubhekele imininingwane: Miguel Ángel Gatón
  2. Inhloso yedatha: Lawula Ugaxekile, ukuphathwa kwamazwana.
  3. Ukusemthethweni: Imvume yakho
  4. Ukuxhumana kwemininingwane: Imininingwane ngeke idluliselwe kubantu besithathu ngaphandle kwesibopho esisemthethweni.
  5. Isitoreji sedatha: Idatabase ebanjwe yi-Occentus Networks (EU)
  6. Amalungelo: Nganoma yisiphi isikhathi ungakhawulela, uthole futhi ususe imininingwane yakho.

  1.   Kunzima okulingene kusho

    Kuhle! Noma kunjalo 2 ukuphawula: Ithegi ye-Ubuntu isigamu kakhulu, njengoba yenza okuthile okujwayelekile. Futhi uma lezi zifundo ziqhubeka nokuthuthuka, kungaba kuhle uma zixhumene ...
    Ngaphandle kwalokho, lokhu kuthutha kuyathakazelisa!

  2.   Masisebenzise iLinux kusho

    Umnikelo omuhle! Kuhle!

  3.   UGiovanni Escobar Sosa kusho

    Kuphela izinkomba ezingekho kulabo abafuna ukungena kakhulu odabeni. Eminye emihle yize kungelula kangako ukuyithola emazweni ethu
    - Umhlahlandlela osebenzayo wemiyalo yeLinux, Abahleli, kanye noHlelo lweShell, uMark Sobell (Isahluko 8)
    - IPro Bash Programming, uChris FA Johnson (yize lokhu kungenxa yalabo abanezinye izinkomba noma ulwazi oluncane).

    I-athikili enhle.

  4.   Masisebenzise iLinux kusho

    Usuku oluhle! Ngiyabonga!

  5.   UPatricio Dorantes Jamarne kusho

    : @ Umsebenzi we- "log in as" ususe ukuphawula kwami ​​kwangaphambilini, ngakho-ke ngizokufingqa ngokuqhubekayo:
    imisebenzi -cp
    bash: imisebenzi: -c: inketho engavumelekile
    imisebenzi: ukusetshenziswa: imisebenzi [-lnprs] [jobspec…] noma imisebenzi -x command [args]

    -eq -gt -lt abamukeli ukuguquguquka kwamaphoyinti wedesimali, phakathi kwesithangami nesithangami ngithole ukuthi i-bc ingumbimbi omuhle:
    uma [`echo 9.999> 10 | bc` -eq 1]; lapho-ke
    i-echo "9.999 inkulu kune-10, qiniseka ukuthi iprosesa lakho lisasebenza"
    futhi
    i-echo «9.999 ayinkulu kuneyishumi, konke kusebenza ngokujwayelekile
    fi

  6.   Hhayi Evela eBrooklyn kusho

    Lokhu okuthunyelwe kufingqa kahle konke okujwayelekile kokubhalwa kwe-bash:
    http://www.aboutlinux.info/2005/10/10-seconds-guide-to-bash-shell.html

    Kuleli sayithi uzothola imibuzo nezimpendulo eziningi mayelana nokuhlukahluka kwe-bash:
    http://unix.stackexchange.com/questions/tagged/bash

    Nayi eminye imibhalo epholile, futhi he, ungayifunda ngokufunda imibhalo yabanye abantu:
    http://snipplr.com/search.php?q=bash&btnsearch=go

  7.   Hhayi Evela eBrooklyn kusho

    Uqinisile ngalokhu okushoyo, ngaphandle kwe-bash. Zonke izinhlelo engizibonile zine-bash in / bin / bash.

    Kepha i-python, i-perl, i-ruby, njll., Kuhle ukuyisebenzisa lokho. Ngiyavuma

  8.   IGuille kusho

    Kwaziqondanela nje ukuthi, ekolishi sisebenzisa ukubhala i-bash ngakho-ke imininingwane iyi-10, yinhle kakhulu!

  9.   alex vi kusho

    inguqulo ye-pdf ongayilanda ingaba yinhle !! 😀

  10.   UMarco Antonio De Fuentes kusho

    Isayithi elihle kakhulu. Ekugcineni ngithole okuthile okuwusizo. Ngiyabonga.