bat script 点滴

Posted my-sky

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了bat script 点滴相关的知识,希望对你有一定的参考价值。

1. 两个%括起来的变量,说明是用的变量的值,而不是变量本身。

  如 set version = "1.0"

      echo version //// print verison in console

      echo %version% ////print 1.0 in console

2. For parameter %%variable IN fittler DO do something

      For has four parameters:

     1) /d(only directory, it means this command will work on the direcoty not file),

     2) /l(迭代数值范围 Iterative numerical range) for /l %%i in (start#, step#, end#) do command, will execute command when start#<end#.

     3) /r(recurrence(递归,遍历), example: for /r c:\ %%i in (*.exe) do @echo %%i )

     4) /f (迭代及文件解析)

 eol=c           - specifies an end of line comment character
                          (just one)
        skip=n          - specifies the number of lines to skip at the
                          beginning of the file.
        delims=xxx      - specifies a delimiter set.  This replaces the
                          default delimiter set of space and tab.
        tokens=x,y,m-n  - specifies which tokens from each line are to
                          be passed to the for body for each iteration.
                          This will cause additional variable names to
                          be allocated.  The m-n form is a range,
                          specifying the mth through the nth tokens.  If
                          the last character in the tokens= string is an
                          asterisk, then an additional variable is
                          allocated and receives the remaining text on
                          the line after the last token parsed.
        usebackq        - specifies that the new semantics are in force,
                          where a back quoted string is executed as a
                          command and a single quoted string is a
                          literal string command and allows the use of
                          double quotes to quote file names in
                          file-set.

    Some examples might help:

FOR /F "eol=; tokens=2,3* delims=, " %i in (myfile.txt) do @echo %i %j %k

      %%variable: it may be a-z or A-Z, and it is case sensitive. For will set its value with any what it gets.

     IN: syntax

3. %* : it presente the parameter passed by command line. %1 means the firlst one, and %2 means the second one, and so on.

4. Interact with users: Set /p variable= [prompt string]. It is very important that must have a whiteplace after the "=". You can use %variable% get users input value.

     

以上是关于bat script 点滴的主要内容,如果未能解决你的问题,请参考以下文章

『神器点滴之ssh』如何优雅的退出ssh

点滴益购商业系统源码

辅导日的点滴积累,希望有更多的点滴...

Phone 7编程点滴

Dubbo点滴之暴露服务解析

关于TVM的点滴记录