Shiryawa a cikin bash - kashi na 1

Duk da yake gabaɗaya muna amfani da shi don gudanarwa ko ayyukan sarrafa fayil, na'ura wasan bidiyo de Linux faɗaɗa ayyukanta nesa da wancan maƙasudin, yana ba mu damar shirin rubutun Ba a nufin wannan jagorar ya zama cikakken bayani game da shirye-shiryen Bash, amma gabatarwa ga umarni da tsari na asali, wanda zai ba mu damar faɗaɗa ikon tsarinmu na GNU / Linux.

Menene "Rubutu"?

Asali muna cewa fayel ne wanda yake dauke da lambar da aka rubuta a cikin wani yare yare wanda tsarin yake amfani dashi don wani aiki. Ba ya buƙatar samun shigarwar waje ko ƙirar zane, amma yana buƙatar haifar da bayanan da aka sarrafa don fitarwa (koda kuwa mai amfani bai gani ba).

Yaren da Bash yayi amfani da shi an fassara shi ta hanyar mai fassarar sa kuma ya haɗu da tsarin amfani da wasu Shells, kamar su Korn Shell (ksh) ko C Shell (csh). Hakanan ana iya amfani da yawancin umarni waɗanda yawanci ana amfani da su a cikin na'ura mai kwakwalwa a cikin rubutun, sai dai waɗanda ke da alaƙa da wani rarraba.

Tsarin Rubutu

Don farawa dole ne mu sami editan rubutu da sha'awar yin shiri. Fayilolin da muka adana tare da .sh tsawo za a iya kashe su (ko a fassara su) ta hanyar amfani da na'urar, idan dai layin farko mai zuwa ne:

#! / bin / bash

Wannan yana gaya wa tsarin yin amfani da na'ura don gudanar da fayil ɗin. Bugu da kari, # halin yana baka damar rubuta tsokaci. Don ƙirƙirar misali mafi sauƙi mun ƙara layi ɗaya, wanda aka gani a hoto mai zuwa:

Amsar amsa kuwwa tana nuna sako akan allo, a wannan yanayin hankula "Barka dai duniya!" Idan muka adana shi kuma muka aiwatar da shi tare da na'ura mai kwakwalwa za mu ga sakamakon.

Umarni na asali

Dokokin masu zuwa suna gama gari kuma suna da matukar amfani ga kowane irin shiri. Mun bayyana cewa akwai da yawa, amma a yanzu zamu rufe wadannan.

Aliases: Yana ba da damar maye gurbin zaren kalmomi zuwa gajeriyar, wanda ke ba da izinin rage lamba.

#kirkiri wani laƙabin da ake kira da tare da adireshin #Downloads folder alias per = '/ home / user / Downloads' # Duk lokacin da muke son amfani da shi sai kawai mu kira # sabuwar kalma ta # Don lalata wannan laƙabin, muna amfani da unalias unalias per

hutu: yana ba ka damar ficewa nan da nan don, yayin, har ko zaɓi madauki (za mu yi nazarin madaukai daki-daki daga baya)

# Kirkirar wani madauki da zai sanya lambobi daga 1 zuwa 5 # ga kowane "juyawar madauki" don kirgawa a cikin 1 2 3 4 5 yi #Muna buga halin yanzu na canji #counter, wanda yake bincikar yanayin $ echo " $ counter ”#Idan farashin abin yayi daidai da 3 idan [$ counter –eq 3] to # Hutu ya fita daga madauki don hutu fi anyi

ci gaba - Kama da karya, sai dai kawai ya yi biris da maɓallin yanzu kuma ya tafi na gaba.

# Kirkiro wani madauki da zai sanya lambobi daga 1 zuwa 5 # ga kowacce "juyawar madauki" ta lissafi a 1 2 3 4 5 yi #Idan farashin lissafin yayi daidai da 3 idan [$ counter –eq 3] to #Ci gaba yana hana sauran abubuwan da suke zagayawa a yanzu daga tsallakawa zuwa zagaye na gaba, ma'ana, ba za'a buga # darajar 3 ba. ci gaba fi amsa kuwwa "$ counter" anyi

shelanta: yana bayyana masu canji kuma ya sanya musu ƙimomi, kamar nau'ikan komputa (suna aiki iri ɗaya). Zamu iya haɗa shi tare da wasu zaɓuɓɓuka: -n bayyana masu adadi; -r don masu canji kawai, waɗanda ba za a iya canza ƙimar su ba; –A don tsararru ko “tsararru”; -f don ayyuka; -x don masu canji waɗanda za a iya "fitarwa" a waje da mahalli na rubutun kanta.

bayyana –i num = 12 bayyana –x pi = 3.14

taimako: yana nuna taimako ga takamaiman umarni.

ayyuka: yana nuna tafiyar matakai.

#Tare da -c muna nuna sunan umarnin, tare da –p # pid (aiwatar id) na kowane tsari. ayyuka -cp

bari: kimanta furucin lissafi

bari a = 11 bari a = a + 5 #A ƙarshe zamu buga ƙimar wanda shine amsa kuwwa 16 "11 + 5 = $ a"

na gida: ƙirƙirar masu canji na gida, waɗanda yakamata a yi amfani da su cikin ayyukan rubutun da kanta don kauce wa kurakurai. Kuna iya amfani da ayyuka iri ɗaya kamar umarnin shela.

na gida v1 = "Wannan canjin na gari ne"

fita: yana ba da izinin fita daga Shell gaba ɗaya; yana da amfani ga shari'o'in da muke aiki tare da taga sama da ɗaya, wanda umarnin fita zai bada izinin ƙare taga ɗaya a lokaci guda.

printf: yana baka damar buga bayanai da tsara shi. Yana da hanyoyi da yawa, don haka zamu ambaci kaɗan.

#% f buga ne a matsayin lambar shawagi, n don sabon # layin buga "% fn" 5 5.000000 # & d yana ba da izinin wuce lambobi goma a matsayin muhawara printf "Akwai umarni% d masu daraja a% d dollars.n" 20 500 Akwai umarni 20 masu daraja a 500 Daloli.

karanta: karanta layi daga daidaitaccen shigarwar (tsarin da aka yi amfani dashi wajen ɗora bayanai ta hanyar maballin misali). Zamu iya wuce zaɓuka kamar: -t don bawa iyakance lokacin karatu; -a domin kowace kalma an sanya ta a wani wuri a cikin jerin gwanon aname; -d don amfani da iyaka wanda za'a rubuta a ƙarshen layin; da sauransu.

amsa kuwwa "Shigar da sunanka ka danna ENTER" # Karanta sunan mai canzawa karanta sunan amsa kuwwa "Sunanka $ sunan"

nau'in: bayyana umarni da halayenta. Zai iya zama da amfani gano ma'anar bayanan kowane umarni.

type –a '[' #type ya gaya mana cewa [umarni ne da aka gina na Shell [shine Shell ya gina # -a yana ba da damar nemo kundayen adireshin da ke dauke da # aiwatarwa tare da rubutaccen sunan. [is / usr / bin / [

ulimit: ƙayyade damar da amfani da wasu albarkatun tsarin don aiwatarwa, manufa don shirye-shiryen da ke ba da izinin canje-canje na gudanarwa ko waɗanda ke fuskantar nau'ikan masu amfani. Lokacin saita iyaka muna rubuta lamba wanda yake wakiltar kilobytes na iyakar.

#Muna ganin iyakokinmu na yanzu ulimit –a # -f yana bada damar iyakance masu amfani da rashin iya # kirkirar fayilolin da suka fi 512000 Kb (500 #Mb) ulimit –f 512000 # -v iyakance mahimmin aikin. ulimit –v 512000

jira: jira wani tsari ko aiki don aiwatarwa.

# Rubutun yana jiran aiwatar da pid # 2585 don aiwatarwa

jira 2585

Sauran umarni masu amfani waɗanda za mu iya ƙarawa zuwa rubutun suna wakiltar alamu.

!!: sake aiwatar da umarni na karshe

! wer: aiwatar da umarnin ƙarshe wanda ya fara tare da kalmar “wer”.

'==', '! =', '>', '<', '> =', da '<=': masu aiki tare.

|: Mai amfani da sabis gabaɗaya yakan haɗu da maganganu biyu na yau da kullun.

: umarnin tsere wanda zai baka damar tsara maganganu. Misali: a don faɗakarwar sauti, n don sabon layi, b don filin baya, da dai sauransu.

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.

10 comments, bar naka

Bar tsokaci

Your email address ba za a buga.

*

*

  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

    Babban! Koyaya, ra'ayoyin 2: Alamar Ubuntu tana da yawa da yawa, saboda yana ƙaddamar da wani abu wanda yake gama gari. Kuma idan waɗannan koyarwar zasu ci gaba, zai yi kyau idan suna da alaƙa da juna….
    Baya ga wannan, wannan motsi yana da ban sha'awa!

  2.   Bari muyi amfani da Linux m

    Kyakkyawan taimako! Babban!

  3.   Giovanni escobar sosa m

    Nassoshin da aka rasa ne kawai ga waɗanda suke son ƙara shiga cikin lamarin. Wasu masu kyau kodayake ba mai sauƙin samu a cikin ƙasashenmu ba
    - Jagora mai amfani ga Dokokin Linux, Editoci, da Shirye-shiryen Shell, Mark Sobell (Fasali na 8)
    - Shirye-shiryen Pro Bash, Chris FA Johnson (kodayake wannan na waɗanda suke da wasu nassoshi ne ko kuma ɗan ƙaramin sani).

    Labari mai kyau.

  4.   Bari muyi amfani da Linux m

    Kyakkyawan kwanan wata! Na gode!

  5.   Patricio Dorantes Jamarne m

    : @ Aikin "shiga kamar yadda" ya share tsokacina na baya, don haka zan ƙara taƙaita shi:
    ayyuka -cp
    bash: ayyuka: -c: ba daidai bane zaɓi
    jobs: amfani: jobs [-lnprs] [jobspec…] ko jobs -x umurnin [args]

    -eq -gt -lt kar su yarda da sauye-sauyen maki goma, tsakanin tattaunawa da tattaunawa Na gano cewa bc abokin kirki ne:
    idan [`` amsa kuwwa 9.999> 10 | bc` -eq 1]; to
    amsa kuwwa "9.999 ya fi na 10 girma, tabbatar cewa mai sarrafa ku yana aiki har yanzu"
    kuma
    amsa kuwwa «9.999 bai fi 10 girma ba, komai yana aiki daidai
    fi

  6.   BaBarBokoklyn m

    Wannan sakon ya taƙaita sosai game da cikakken rubutun bash:
    http://www.aboutlinux.info/2005/10/10-seconds-guide-to-bash-shell.html

    A kan wannan rukunin yanar gizon zaku sami tambayoyi da amsoshi da yawa game da abubuwan ban mamaki:
    http://unix.stackexchange.com/questions/tagged/bash

    Anan akwai wasu rubutun kwarai da gaske, kuma hey, zaku iya koyon su ta hanyar karanta rubutun wasu mutane:
    http://snipplr.com/search.php?q=bash&btnsearch=go

  7.   BaBarBokoklyn m

    Kunada gaskiya da abinda kuke fada, banda bash. Duk tsarin da na gani yana da bash a / bin / bash.

    Amma don Python, perl, ruby, da sauransu, yana da kyau a yi amfani da hakan. Ina yi

  8.   Guille m

    Ba zato ba tsammani, a cikin kwaleji muna amfani da rubutun bash don haka bayanan 10 ne, suna da kyau sosai!

  9.   alex na gani m

    sigar pdf don zazzagewa zaiyi kyau !! 😀

  10.   Marco Antonio De Fuentes m

    Da kyau site. A ƙarshe na sami wani abu mai amfani. Na gode.