ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • CMD 배치 스크립트
    프로그래밍 언어/스크립트 언어 2014. 3. 10. 15:51

    command shell

    the command interpreter Cmd.exe

    the Windows Script Host, CScript.exe


    a .bat or .cmd file name extension


    * 도스 프롬프트에서 실행 가능한 모든 명령어들

    c.f. conditional processing symbols



    - the Windows NT command interpreter

    In a batch file, the @ symbol is the same as ECHO OFF applied to the current line only.


    C:> VER


    C:> HELP


    C:> HELP set



    - Filter commands

    more

    find

    grep?

    findstr

    grep

    sort


    - redirection operators


    e.g.

    for %f in (*.bat) do find "PROMPT" %f 


    dir c:\ /s /b | find "CPU"


    dir>c:\file.txt 2>&1


    * 배치 파일에서만 전용으로 사용되는 명령어들

    > 디렉티브(?)

    ECHO [{ON|OFF}] [message]

    Turns the command-echoing feature on or off, or displays a message.


    REM

    주석


    레이블(?)

    c.f. GOTO


    > 파라메터(변수)

    %0, %1, %2, %3, %4, %5, %6, %7, %8, %9

    To access arguments beyond %9, you need to use the shift command.


    modifiers and qualifiers

    %~f1    - Expands %1 to a fully qualified path name.


    이름을 가진 변수(NAMED VARIABLE)

    앞에 %(퍼센트 기호)를 두 개 붙여 준다

    변수명으로는 한 문자로된 알파벳만을 사용할 수 있다


    >

    environment( variable)


    set

    With string assignments, there must be no spaces before and after the equality sign.

    e.g. set varname=new^&name


    Substituting environment variable values

    %variablename%


    setlocal

    endlocal


    >

    PAUSE


    > 제어문

    IF EXIST

    e.g. IF EXIST C:IF_ONE.TXT PRINT C:IF_ONE.BAT


    IF NOT EXIST

    e.g. IF EXIST %2 PAUSE Target file already exists copy %1 %2


    IF String1==String2

    e.g.

    IF %1==BOSS ECHO YOU ARE A BOSS...!

    IF "%1"=="HERO" ECHO ARE YOU A HERO...?


    IF NOT String1==String2


    IF ERRORLEVEL

    탈출 상태 코드(EXIT STATE VALUE)가 주어진 값보다 크거나 같으면


    e.g.

    IF NOT ERRORLEVEL


    FOR IN () DO

    e.g. FOR %%I IN (*.BAT) DO TYPE %%I


    CALL


    GOTO

    c.f. 레이블


    SHIFT

    e.g.

    CHOICE

    e.g. choice /c:ync YES, NO, or Continue



    -
    32-bit Windows commands


    참조 사이트:


Designed by Tistory.