Cov txheej txheem:

Coding Nrog Batch: 7 Kauj Ruam
Coding Nrog Batch: 7 Kauj Ruam

Video: Coding Nrog Batch: 7 Kauj Ruam

Video: Coding Nrog Batch: 7 Kauj Ruam
Video: Mob nrob qaum/ Mob duav yog vim li cas? 2024, Hlis ntuj nqeg
Anonim
Coding Nrog Batch
Coding Nrog Batch

Ua ntej peb pib

Batch yog hom lus sau ua los ntawm Microsoft. Nws yog qhov yooj yim heev, vim tias nws tsis tuaj yeem tso duab, lossis ua suab. Txawm hais tias, nws muaj txiaj ntsig qhib daim ntawv thov, ua cov ntawv ua si, thiab siv raws li lub moos thib ob.

Nws yooj yim kawm, vim tias tsis muaj ntau cov lus txib yog tias koj xav ua qee yam nrawm.

Phau ntawv qhia no yuav piav qhia qee qhov lus txib yooj yim, nrog rau kev qhia yuav ua li cas thiaj ua lub moos.

Nco tseg: Batch tsuas ua haujlwm ntawm windows systems los ntawm DOS hnub, mus rau qhov tshiab tshaj plaws ntawm Windows. Yog li tsis txhob sim Unix raws cov kab ke (Linux, android …) lossis MacOS's (iOS, Mackintosh).

TSEEM CEEB:

THAUM SAWV DAWB COV NTAUB NTAWV YUAV UA LI CAS YUAV TSUM MUAJ TSEEB NROG ".bat" LOS YOG ".cmd" (Tus kheej, kuv nyiam. Puav)

Tsis tas li, yog tias koj xav kho nws, koj tuaj yeem nyem txoj cai> Kho kom raug, txhawm rau kho cov ntaub ntawv kom qhib hauv Notepad. Yog tias koj siv lwm yam, zoo li Sublime Text, lossis Notepad ++, koj feem ntau tuaj yeem mus rau File> Qhib … thiab pom cov ntawv nyob ntawd, yog tias nws tseem tsis tau thauj khoom.

(Rau Notepad ++ cov neeg siv, koj tuaj yeem nyem txoj cai> Kho nrog Notepad ++ kom yooj yim siv.)

(Thov txim rau cov duab daws teeb meem tsawg. Xav tau daim duab thiaj hais tias "Qhov no yuav ua" thiab muab tso rau ntawd.)

Kauj Ruam 1: Cov Hauv Paus | Echo

Qee cov lus txib yuav tsis tu ncua hauv txhua yam koj ua.

Thawj ntawm cov no yuav yog "ncha".

Echo ua dab tsi?

Qhov tseem ceeb, nws xa tag nrho cov ntawv koj nkag mus. Piv txwv li, yog tias koj tso "echo Nyob Zoo!" mus rau qhov hais kom ua sai sai, koj yuav tau txais "Nyob zoo!" raws li qhov tso tawm.

Echo kuj tseem tuaj yeem tua tau.

Qhov no ua tiav yooj yim los ntawm kev mus "@echo tawm". Qhov no nres nws los ntawm kev xa cov ntaub ntawv zoo li "C: / windows / System32 (yog tias koj tab tom khiav nws hauv hom thawj coj).

Kauj Ruam 2: Kauj Ruam 2: Hauv paus | Xim thiab Cls

Xim yog tus kheej piav qhia. Nws tso cai rau koj hloov xim font thiab xim tom qab ntawm lub qhov rai davhlau ya nyob twg. Kev piav qhia ntxaws ntxiv tuaj yeem nrhiav pom los ntawm kev ntaus "xim?" mus rau qhov hais kom ua sai sai (cmd.exe)

Cls yog luv luv rau "Clear Screen". Nws so lub vijtsam ntawm txhua cov ntaub ntawv yav dhau los, xws li sau cov lus txib, ntawv, thiab ntxiv rau.

Kauj Ruam 3: Kauj Ruam 3: Hauv paus | "%%", ":" thiab Goto

Nov yog qhov uas tau txais kev txaus siab.

Nrog "%%", koj muaj peev xwm khaws qee cov ntaub ntawv, xws li nkag cov ntawv lossis lwm yam stats kom txog thaum lub console raug tshem tawm (kaw), muaj txiaj ntsig hauv qee cov ntawv sau. (Hauv kev ua si raws cov ntawv, koj tuaj yeem siv qhov no los cawm cov npe, stats, thiab lwm yam tuaj yeem hloov kho thiab taug qab.)

Nrog ":" thiab mus, koj tuaj yeem tsim cov loops, thiab txav mus ib ncig ntawm tsab ntawv. Yog li, koj tuaj yeem muaj tus neeg siv nkag mus rau qee yam, tom qab ntawv tshem tawm tsab ntawv lossis rov qab mus rau qhov pib.

Kauj Ruam 4: Kauj Ruam 4: Hauv paus | Thaum kawg

Muaj ob peb yam ntxiv uas koj yuav tsum nco ntsoov ua ntej mus.

set /p insertsomethingherehere = Sau cov ntawv:

yog %insertsomethinghere %== 1 goto aplacetogo

Qhov no tuaj yeem siv los ua kev xaiv xaiv ntau yam. Nkag mus rau qee qhov lus teb, thiab coj mus rau cov lus teb sib txawv.

Xwb, {set /p insertaname = Thov sau lub npe:

yog%insertaname%==%insertaname%goto nextstep}

Qhov no yuav txuas ntxiv mus rau qib tom ntej, yam uas yuav yog.

Faj seeb: Txhua yam hauv daim ntawv siab ntawm nplooj ntawv no tsis xav tau. Txhua yam hauv cov haujlwm no yuav txawv. Txhua yam uas tau hais tseg tuaj yeem luam tau ntau zaus raws li xav tau.

Nco tseg tshwj xeeb: nyob nruab nrab ntawm {} cov khoom sib dhos, qhov no yog cov txuj ci txhua yam koj xav tau. Txawm hais tias koj tuaj yeem muaj lub npe tshwj xeeb uas muab txiaj ntsig tshwj xeeb rau koj, cov cim paub koj, lossis koj muaj lwm txoj hauv kev. txhua yam koj yuav tsum tau ua yog ntxiv "yog %insertaname %== Bob goto nextstepbob" (koj yuav tsum tau ntxiv txoj kev sib txawv uas yuav ua rau muaj kev cuam tshuam, lossis tsuas yog muab txoj hauv kev me me, uas, yuav txuas rov qab nrog lub ntsiab thaum kawg.)

Kauj Ruam 5: Kauj Ruam 5: Qee Qhov Lom Zem | Ib lub moos

Nov yog qee yam kuv tau kawm ua ntej, qhov tseeb.

@echo tawm

siv 0a

cls ua

: moos

echo Lub sijhawm tam sim no yog %sijhawm %thiab hnub tim yog %hnub %

mus moos

Xaiv tau, koj tuaj yeem tso "cls" tom qab: moos

Txawm hais tias qhov no yuav ua rau nws flicker thiab yog qhov txaus siab me ntsis.

Nco ntsoov khaws kom raug!

Kauj Ruam 6: Kauj Ruam 6: Thaum kawg …

Tam sim no, Kuv tau ua haujlwm ntawm kev ua si. Hauv qab no yog qhov kuv muaj tam sim no.

Nws yog qhov yooj yim, thiab tuaj yeem ua si me ntsis, txawm hais tias tsis txawm nyob ze qhov kuv xav ua.

(Vim li cas nws txiav txim siab los ua cov ntawv, Kuv yuav muab nws yog tias muaj kev thov.)

Kauj Ruam 7: Kev Pab Ntxiv

Xav nug seb koj puas nyam ntawm qee yam. Kuv yuav sim pab sai li sai tau.

Ua tsaug rau kev nyeem ntawv, thiab vam tias qhov no yuav pab tau.

Pom zoo: