zoukankan      html  css  js  c++  java
  • 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.

    5. The %~dp0 variable : The %~dp0 (that’s a zero) variable when referenced within a Windows batch file will expand to the drive letter and path of that batch file.The variables %0-%9 refer to the command line parameters of the batch file. %1-%9 refer to command line arguments after the batch file name. %0 refers to the batch file itself.If you follow the percent character (%) with a tilde character (~), you can insert a modifier(s) before the parameter number to alter the way the variable is expanded. The d modifier expands to the drive letter and the p modifier expands to the path of the parameter. Example: Let’s say you have a directory on C: called bat_files, and in that directory is a file called example.bat. In this case, %~dp0 (combining the d and p modifiers) will expand to C:at_files.

         

  • 相关阅读:
    如何编写测试用例
    bug的合规描述
    Linux常用命令学习
    测试用列设计
    软件质量管理
    测试的分类
    软件工程模型
    软件测试核心概念
    Thinking in C++ 第十三章 动态对象创建
    python urllib
  • 原文地址:https://www.cnblogs.com/my-sky/p/8393360.html
Copyright © 2011-2022 走看看