Bash: Yadda ake yin rubutun aiwatarwa

Ina so kadan-kadan in sanya labarai a kai BashDa kyau, Ina da isassun kayan da zan koya muku kadan da kadan, sanya rubutu, da ƙari, don ayyukanmu na yau da kullun su kasance na atomatik, don haka a bayyane zai adana mana lokaci mai yawa 😀

Yanzu zan nuna muku abubuwan yau da kullun, abin da koyaushe zaku buƙaci sani, kuma hakan zai taimaka min game da sauran koyarwar 😉

Yadda ake yin rubutun .sh?

Mai sauƙi ... mai sauƙin gaske 😀

1. Bude m, a ciki rubuta mai biyowa ka latsa [Shiga]:

cd $HOME && touch script.sh && chmod +x script.sh

Wannan zai isa ya ƙirƙiri musu fayil rubutun.sh a cikin babban fayil.

2. A cikin tashar sa waɗannan masu zuwa:

cd $HOME && echo '#!/bin/bash' > script.sh && echo '# -*- ENCODING: UTF-8 -*-' >> script.sh

3. Shirya, kun shirya rubutunku 😀

Idan muka bude shi, zamu sami wani abu kamar haka:
#!/bin/bash
# -*- ENCODING: UTF-8 -*-

Bayan wannan layi na biyu, daga can an rubuta umarnin.

Misali, za mu gaya maka ka nuna mana a cikin tashar mota «<° Linux shine mafi kyau»😀

Muna da rubutun kamar haka:
#!/bin/bash
# -*- ENCODING: UTF-8 -*-
echo "<° Linux es lo mejor"
exit

Yadda ake gudu ko gwada rubutun .sh?

1. Dole ne mu je babban fayil ɗin da rubutun yake, a misalin da ya gabata zai zama babban fayil ɗinmu ne, don haka muka buɗe tashar, a ciki muke rubuta abubuwa masu zuwa kuma danna [Shiga]:

cd $HOME

2. Yanzu muna aiwatar da shi ta hanyar sanya aya da kuma yankan (bi), kuma muna bin sunan rubutun, wannan shine:

./script.sh

Kuma wasan bingo, tuni munada shi 😀

Yi shi kuma zaka gani ...

Yanzu muhimmin daki-daki, a ƙarshen ya kamata koyaushe su sanya «fita«

Kuma da kyau yanzu, babu wani abin da za a ƙara, kawai jira koyarwar nan gaba, a nan za ku koya Bash HAHA.

gaisuwa


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

57 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.   Oscar m

    Na gode aboki, koyaushe ina son sanin yadda ake yin rubutun.sh, yanzu lokaci yayi da za a koya, Zan jira koyawa na gaba.

    1.    KZKG ^ Gaara <"Linux m

      Nah, wani jin dadi hehe 😀
      Za ku gani ... kadan da kadan zan rika sanya Bash Tutorials, don ganin idan wani yayi murna, koya kuma duk mun samu ingantacciyar HAHA.

      gaisuwa

      1.    jose m

        Barka dai, zan bukaci taimakon ku idan zaku iya taimaka min da wasu rubutun da na makale kuma ina buƙatar yin wani fanni, Ina son saduwa da ni.
        Na gode sosai a gaba

  2.   launin ruwan kasa m

    Ah mutum !! mai girma 😉

    1.    KZKG ^ Gaara <"Linux m

      Godiya 😀
      Ka tuna cewa koke ko shawarwari koyaushe za a karɓe su da kyau 😉

  3.   tarkon m

    Ina son post din, duk lokacin da nake bukatar rubutun kai sai na hau zirga zirga kawai don nemo layin: "#! / Bin / bash" a cikin rubutun (Ina mai mantuwa sosai). Yanzu da wannan gudummawar zan iya rubuta shi kuma kwafa da liƙa just kawai

    1.    KZKG ^ Gaara <"Linux m

      Ka tuna cewa / bash ne da / sh ... haha ​​ce ta daban, sau daya na taba yin kwana 2 ina fada da rubutun da baiyi min aiki ba kamar yadda ya kamata, kuma hakan ya faru ne saboda na sanya sh maimakon bash 😀

      Duk wata tambaya da zaku fada mana.
      gaisuwa

  4.   xfraniux m

    Jaajajajajaja kuma wannan shine mafi sauki, zaku iya buɗe gedit ko kowane edita ku kwafa:

    #!/bin/bash
    # -*- ENCODING: UTF-8 -*-
    echo “<° Linux es lo mejor”
    exit

    Sannan kuma muna ba shi izinin aiwatarwa….

    kyau sosai .. gaisuwa

    1.    KZKG ^ Gaara <"Linux m

      hehe ee, da an iya yin hakan, amma ban sani ba ... Ina tsammanin zai fi sauki a yi kwafi / liƙa layuka biyu (wanda a zahiri na iya zama ɗaya) kuma shi ke nan, a shirye rubutun tare da izinin izini da taken

    2.    Bertholdous m

      Barka dai.Ya kamata a adana rubutun koyaushe azaman fayil .sh?

      A cikin windows kwatankwacinsa zai zama fayilolin .bat. Kuma game da rubutun su, suna da ɗan sauƙi.

  5.   Lucas Matthias m

    Yayi kyau sosai

    1.    KZKG ^ Gaara <"Linux m

      Godiya 😀

  6.   artur molina m

    Ina fatan zuwa rubutu na gaba kuma ga ɗan lokaci na lura.

    1.    KZKG ^ Gaara <"Linux m

      😉
      Duk wata shawara, rubutun da kuke so in yi ko wani abu? 😀

  7.   Jaruntakan m

    Shin wannan shine wanda bai san yadda ake shiryawa ba? Kodayake abu ne mai sauki, amma shirye-shirye ne

    1.    KZKG ^ Gaara <"Linux m

      HAHAHA tazo ... shin kana birgewa? ... koya ɗan Bash, za ku ga yadda yake da kyau, ba kwa buƙatar sanin yadda ake shiryawa, ƙasa da haka

      Me kike ce?

      1.    Jaruntakan m

        Zan yi, yau ba don wannan ba

  8.   m m

    A zahiri, idan ana ƙirƙirar rubutun a kai a kai, aikin da kansa shima ana iya sarrafa kansa tare da rubutun kamar haka (ana kwafa shi zuwa $ gida / bin / kuma ana ba shi izinin aiwatarwa)


    #!/bin/sh
    # nuevoscript
    if [ $# -eq 0]; then
    DEST=$HOME
    SNAME=script.sh
    elif [ $# -eq 1]; then
    DEST=.
    SNAME="$1"
    else
    echo "Parámetros incorrectos"
    exit -1
    fi
    echo -e '#!/bin/bash\n# -*- ENCODING: UTF-8 -*-' > "$DEST/$SNAME" && \
    chmod +x "$DEST/$SNAME"
    echo "Creado el script $DEST/$SNAME"
    exit 0

    Ta wannan hanyar, idan kun gudu sabon rubutu ba tare da sigogi ba, ƙirƙiri $ gida / rubutun.sh, amma idan ta gudu sabon rubutun wani rubutun, halitta . / wani rubutu

  9.   ramses m

    Barka dai aboki, Ina son sanin yadda zan kirkiri abin sdcard kuma wayata zata karanta shi da irin wannan android kuma idan aka zartar dashi sai na fara abd.exe tare da umurnin bugreport> bugreport.txt

    1.    KZKG ^ Gaara m

      Babu ra'ayin aboki ... Ban taɓa amfani da Android ba.

  10.   Neo61 m

    Na gode Gaara, Ina so in sami wurin da za a koya mani wasu rubutun, ina tsammanin a cikin imel ɗin da na ambata muku wannan, wanda ainihin abin da nake buƙatar koya ne. Na bi matakan dalla-dalla kuma komai yayi daidai amma baya gudu, na sami wannan:

    ./script.sh: layi na 5: EOF mara tsammani yayin neman daidaitawa '»'
    ./script.sh: layin 9: kuskuren aiki: ba a yi tsammanin ƙarshen fayil ɗin ba

    Bayyana min menene ɓata na

    1.    KZKG ^ Gaara m

      Laifi na, WordPress ya canza wasu bayanai, sake duba lambar a cikin gidan kuma sanya shi kamar haka a rubutun ku.
      Abin da ya faru shi ne:

      "Asd"

      Ba daidai yake da:
      "asd"

  11.   Neo61 m

    Ban fahimta ba, har yanzu ina ganin hakan. Ina canjin yake? Za a iya bayyana mani da kyau? Yanzu idan ka bashi damar aiwatarwa, wannan layin yana fitowa:
    ./script.sh: layi 5: °: Fayil ko kundin adireshin babu

    1.    KZKG ^ Gaara m

      Wuce min rubutun da kakeyi, sanya lambar anan: http://paste.desdelinux.net
      Sake duba post ɗin, shine na manta da danna maɓallin Sabuntawa 😀

  12.   Neo61 m

    Barka dai aboki:
    Zan gaya muku cewa ina kallon rubutun conkyrc din da kuka yi don kwazon ku na 2010 kuma idan, gaskiya ne, alamar diski na wani tushe ne da ake kira Poky amma ba ta zuwa ta asali a libreOffice a Ubuntu 12.04, zai yi kyau, idan kuna da wannan tushen , gaya mani inda zan iya zazzage ta daga (wani abu mai ɗan wahala, da gaske), abu ɗaya da na fahimta shi ne cewa idan aka sanya haruffan waɗannan alamun kuma font babu a cikin tsarin, to yana sanya harafin, ba alama ba, Yana da ma'ana, na riga na fara fahimtar yadda komai ke aiki, amma ina buƙatar wani ya bayyana min abubuwa don in fahimce shi da kyau, duk abin da nake yi ta hanyar ragi ne kuma ban taɓa ba da wani shiri ba, ba ilimin komputa bane abin da na karanta Hakanan, wani lokacin ne, na yi lissafin ne a matsayin abin sha'awa kuma abin farin ciki shine ina aiki a ɗaya daga cikin rassanta, duk abin da na koya an koyar da kaina ne, saboda haka sha'awar wani wanda, ko da da kaɗan, Ka shiryar da ni. a nan kuma rubutun abin banƙyama ne kuma zan bayyana abin da ban samu ba:

    Duba, lokacin da nayi kokarin saka wani HDD sai naci gaba da samunsa iri daya saboda yana bada kimar zafin jiki iri daya. Ba ni da halayen CPU a cikin tsarin, yana fitowa (NULL) da ƙarfi, lokacin da na yi ƙoƙarin saka kalandar da kuka sanya a cikin Conky cewa tanias a cikin 2010 ba ta da tsari kuma tana faɗaɗa sandar conky. Duba don ganin duk ci gaban da za ku iya yi. Ina son shi da faɗin da nake da shi kuma kalandarku ta dace da wannan faɗin kuma duk abin da na gaya muku wanda bai nuna ba ya fito, a nan ya ci gaba:

    http://paste.desdelinux.net/4552

    –Saka lambar a manna mu, don haka maganganun basu da yawa--

  13.   GONZALO m

    gaskiyar ita ce gudummawar ku abin nadama ne

  14.   edgar m

    Barka dai, kun sauƙaƙa rayuwata da wannan rubutun. Na gode kwarai da gaske don ina so in san ko za ku iya turo min da imel inda za ku bayyana ta tun da ni nevo a cikin wannan shirin.
    Gracias

    1.    KZKG ^ Gaara m

      Sannu,
      Mafi kyau Ban iya bayyana / bayyana waɗannan layukan lambar ba, menene ba ku fahimta ba don bayanin ta wata hanyar?

      Hakanan, idan kuna da shakka, kuna iya tambaya koyaushe a cikin dandalinmu: forum.desdelinux.net

      Gaisuwa 😀

  15.   Cesar m

    Kyakkyawan gudummawa amma kuna iya tattara shi ... Ina bukatan rubutu don sai. Wannan shine, lokacin da Sai ya fahimci cewa yana kan batir kuma yana da minti 20 don kashewa, sai ya aika sigina zuwa wata na'urar kuma hakan dole ne ta aiwatar da rubutun don kashe wasu sabobin. Ban sani ba ko na yi bayanin kaina da kyau ... Valdria tare da sanya a cikin rubutunku «shutdown -h» ??

    Gracias !!

  16.   Yesu isra'ila mai perales martinez m

    Wani abu kuma don ƙarawa zuwa babban fayil ɗin samfuri na: B

  17.   Edward m

    Shin wani zai taimake ni Ina buƙatar rubutun don ubuntu cewa idan muka rufe burauzar Chrome, buɗe shi kuma

    Godiya a gaba

  18.   Edo m

    Ina bukatan rubutun cewa ta hanyar aiwatar dashi ne kawai zai sake rubuta bayanan wani file tare da wani rubutu, shin akwai wanda yasan yadda yake?

    1.    Edo m

      Na riga na ga cewa a sama suna faɗin yadda za a yi

  19.   Dario m

    Yayi kyau, kwarai da gaske ga jikoki na.
    Dubun godiya. »Kamar yadda kuma kana da matasa da yawa, aiki a matsayin malami it. Zai zama abin birgewa.

  20.   Roman PC m

    Mai sauƙi da aiki, kamar yadda ya kamata.

    Godiya ga rabawa.

    Na gode.

  21.   Hernan Jaramillo m

    Na gode da taimakon ku. Ya kasance mai amfani, kyakkyawan bayani.

  22.   mataimakin m

    Na gode da yayi min aiki. Murna

  23.   Wasanni m

    Mai sauƙi da tasiri. Babban koyarwa ga sababbi 🙂

  24.   Luis Carlos ne adam wata m

    Barka dai, nasan kadan game da rubutun kuma ban sani ba idan ra'ayoyi masu rikitarwa ne amma abinda nake kokarin yi shine a cikin shafin yanar gizo mai zuwa:
    http://beginlinux.com/blog/2010/03/iptables-with-network-card-aliases/

    Ma'anar ita ce ban fahimci yadda ake fara wannan lambar ba ko kuma idan wannan ya maye gurbin IPTABLES. Kuma idan ya maye gurbinsa kamar yadda yake don ya fara atomatik tare da OS.

    Gracias

  25.   Cris m

    Gaara mai ban tsoro !!!

    Na fara aikin gida kamar yadda kuka yi bayani kuma ya yi aiki !! Na gode da daukar lokaci da kuma raba iliminku don fita daga duhu tare da jahilai.

    😉

  26.   Leo m

    Barka dai, Ina da wasu tambayoyi don yin rubutun da mai amfani ya ƙirƙira, za ku iya taimake ni?

  27.   giovani m

    hello Ina da tambaya tare da .sh file
    kuna da wata hanya cewa
    Na tuntube ku don ganin idan na yi daidai ne?

    #! / tsarin / bin / sh
    Dutsen -o remount, rw /
    mkdir /mnt/local/Android/data/org.xbmc.xbmc/files/.xbmc
    ln -s /mnt/local/Android/data/org.xbmc.xbmc/files/.xbmc /.xbmc
    Dutsen -o remount, ro /

    , Ina sarrafa shi da hannu a cikin tashar kuma idan yana aiki, amma lokacin da nake son fayil ɗin ya gudana baya so.

  28.   louis m

    Na sami wannan a vivaolinux.com.br, yana da kyau

    #! / bin / bash

    Dogaro da Gera.sh - Gera cabeçalho don rubutun

    Rubutawa: Sandro Marcell P. Barbosa (Boa Vista - Roraima)

    E-mail: sandro_marcell@yahoo.com.br

    Slackware GNU / Linux 10.1.0

    Misalin amfani: script_name my_script

    Hakanan zaka iya ƙayyade tsawo, dacewa ko mai fassara.

    Ex.: Nome_script backup.sh domin o mai fassara 'sh'

    ou nome_script backup.tcl ga mai fassara 'tcl' sannan kuma ranar!

    Bayyana mai fassarar za ku iya (maimakon wani!):

    FASSARA = »#! / Bin / sh»

    Abun cikin kai (canza kamar yadda kake so!):

    INFO = »##»
    MAHALICCI = »## Rubutawa:»
    EMAIL = »## e-mail: you@correo.com»
    DISTRO = »##»

    Dubawa idan mai amfani ya ƙayyade sunan rubutun:

    idan [$ # -eq 0]; to
    amsa kuwwa ">>> Amfani: $ (sunan laƙabi $ 0)"
    fita
    fi
    idan [$ # -ge 2]; to
    amsa kuwwa "Suna tare da sarari ba su da inganci!"
    fita
    fi

    Shin mai amfani zai iya yin rubutu zuwa kundin adireshi na yanzu?

    idan [! -w $ PWD]; to
    amsa kuwwa "Babu izinin rubuta kundin adireshi na yanzu!"
    fita
    fi

    Mene ne idan akwai wani rubutun tare da suna iri ɗaya a cikin kundin adireshi na yanzu?

    idan [-f $ 1]; to
    amsa kuwwa "Rubuta mai suna iri ɗaya ya riga ya kasance a cikin wannan kundin adireshin!"
    fita
    fi

    Rubutun jiki:

    (
    cat << KARSHE
    $ FASSARA

    $ INFO
    $ MAHALICCI
    $ EMAIL
    $ DISTRO

    Yanzu ƙara umarni a cikin layi na gaba =)

    Ranar ƙirƙirar wannan rubutun: $ (kwanan wata «+% a% d /% m /% Y») a $ (kwanan wata «+% T»)

    Fin
    )> $ 1

    Kafa aiwatar da izini:

    idan [-f $ 1]; to
    chmod + x $ 1 2> / dev / tsayi
    amsa kuwwa "Rubutun $ 1 da aka kirkira kuma aka bashi damar aiwatarwa!"
    fi

    Ranar kirkirar wannan rubutun: 29/01/2013 19:45:00

    1.    debianistrowler m

      Mai girma, yana aiki daidai !!!

  29.   Vincent m

    Kyakkyawan koyawa, mai sauƙi kuma ya taimaka min sosai, godiya

  30.   calichi m

    Ya ƙaunataccen KZKG ni sabon shiga ne, amma ina sha'awar koyo.
    Kuna da sauran rubutun. Ko kuma ba zato ba tsammani a wurin da nake aiki ina so in buɗe wanda aka tattara kuma ba zan iya gani ba.
    Duk wani ra'ayi.

  31.   calichi m

    Ina bukatan taimako tare da rubutu. An tattara

  32.   sanyi9 m

    Na fahimta game da bash, amma idan naso in sanya masa suna ta atomatik baya fitowa

  33.   angiesarite m

    Na gode sosai don taimakon aboki.

    Ina so in san ko zaku iya yi min wata babbar ni'ima, Ina buƙatar ƙirƙirar rubutun da zai taimaka min ƙirƙirar .sum a wani lokaci amma ban san yadda zan tsara shi ba. Kuna iya taimaka min da wasu abubuwan nunawa. Godiya kuma zan mai da hankali idan zaku iya taimaka min.

    gaisuwa

  34.   José m

    Barka dai barka da rana, duba, Ina yin aiki a Lex, don haka ina so idan zaku iya taimaka min da Rubutu, wanda zan iya aiki da fayil ɗin Lex, wanda Lex ke samarwa (Lex.yy.c) da fayil ɗin shigar da bayanai .

    Muchas gracias

  35.   Wilmer Ron m

    watercress godiya doc !!! Ni sabo ne ga rubutun na gode sosai gaisuwa zan kasance a kan ido tare da sabon koyarwar ku !!!!

  36.   Karen vega m

    Hola !!!

    Na gode sosai da gudummawar da kuka bayar, na fara shigowa cikin unix kuma da wuya wani ya yi bayanin wannan duniyar ta hanya mai sauƙi. Ina so in tambaye ku idan tare da aikin ku zan iya yin rubutun da zai taimake ni in sami n yawan fayilolin da suke rayuwa a kan hanya ɗaya, kuma in kwafe su zuwa wani babban fayil ... wani ya gaya mani cewa zan iya adana a cikin txt hanyar da sunan fayiloli na, amma ba a bayyana mini yadda zanyi ba. Ina saurara sosai.

    Saludos !!

  37.   Eibar Amaya m

    Barka dai Ina da VPS amma ina bukatan taimako a wasu abubuwa ko kuma ni kaina Ina sha'awar yadda zan kirkiro rubutu ko wani abu domin inyi aiki da kai na na komai na cikin folda na / tushenta kuma wannan madadin yana gudana duk bayan awa 1 idan na za ku iya taimakawa a cikin wannan zan gode muku da yawa a cikin hakan

    Na bar muku facebook dina in kuna son taimaka min ina bukatar taimako sosai 🙂

  38.   Hoton Jorge Rodriguez m

    ƙirƙira ni ɗaya don ping da saka idanu kan wasu kayan aikin sadarwa a cikin kamfanin
    amma na sauƙaƙa shi

    taba red.sh && chmod + x red.sh
    jefa '# -- LAYYA: UTF-8 -- '>> ja.sh
    amsa kuwwa 'ping 10.50.0.125 -w 5' >> red.sh
    amsa kuwwa 'ping 10.50.0.80 -w 5' >> ja.sh

    gudanar da shi ./red.sh kuma lafiya

  39.   Guillermo m

    Masoyi, Ina buƙatar ƙirƙirar rubutun shigarwa ta atomatik. A shirye nake in biya kudin aikin da nayi sosai. Wadanda suke da sha’awa, sai su aiko min da sakon Imel carranzalh@gmail.com. na gode

  40.   sariya m

    suna tsotse zakara na XD

  41.   HDxz m

    Aboki na da safe, za ku iya taimaka min da wani abu
    Ina buƙatar yin madadin tare da Linux na kamfanin tunda yana da aminci don kada ƙwayoyin cuta su kama shi amma ban san yadda zan yi su ba
    Ina buƙatar ƙirƙirar rubutu wanda zai tattara fayilolin kuma aika su zuwa ftp

    Ina godiya a gaba rubuta zuwa imel

    cesarloscor@gmail.com

bool (gaskiya)