批处理

@echo
  @echo on
  该命令之后的任何语句执行结果都打印

  @echo off
  该命令之后的任何语句执行结果都不打印

  只打印statements4,statements5的执行结果

@echo off 
statements1
statements2
statements3
@echo on 
statements4
statements5


变量
  设定变量值
  将第一个参数值设定给变量var

set var=%1

  字符串截取
  截取username_temp从第2个到倒数第2个之间的字符串,并将截取结果赋予username

set username=%username_temp:~1,-1%

  注:此处无法直接使用传递的参数
    若想要将接收的第1个参数的第1个字符串和最后1个字符串去除,如下方式无法得到想要的结果
    例如,假设%1的值为"tom",则

set username=%1:~1,-1%
echo username #输出:"tom":~1,-1%, %1的值与字符串:~1,-1%"的拼接结果

    正确方式为:

set username_temp=%1 #先将参数赋值给一个临时变量
set username=%username_temp:~1,-1% #输出:tom

参数传递
  %1 第1个参数
  %2 第2个参数
  ...
  %n 第n个参数

  注:如果参数本身包含逗号或空格,会影响参数的获取,解决办法是将调用脚本时,将每个参数用双引号括起来,脚本中接收参数时,将双引号去除,如:
    test.bat

@echo off
set username_temp=%1
set password_temp=%2
set username=%username_temp:~1,-1%
set password=%password_temp:~1,-1%

echo user is %username%
echo password is %password%

    命令行

test.bat "my name" "this,is,a,password"  
#输出:user is my name
#输出:password is this,is,a,password
原文地址:https://www.cnblogs.com/shiliye/p/12096519.html