批处理参数:%1 之后的所有内容 [英] batch parameters: everything after %1

查看:27
本文介绍了批处理参数:%1 之后的所有内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

重复:

澄清:我知道循环方法 - 这甚至在命令扩展之前就有效;我希望有一些有趣的和未记录的东西,比如 %~*1 或其他什么——就像那些记录在 http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/percent.mspx?mfr=true.

<小时>

在 Windows 批处理文件中(启用了所谓的命令扩展"),%1 是第一个参数,%2 是第二个参数,等等.%* 是连接的所有参数.

我的问题:例如,有没有办法在 %2 之后获取所有内容?

我找不到这样的东西,这对我正在做的事情会有帮助.

解决方案

我不确定是否有直接命令,但您始终可以使用简单的循环和移位来获取变量中的结果.类似的东西:

<前>@回声关闭设置 RESTVAR=转移:loop1如果 "%1"=="" 转到 after_loop设置 RESTVAR=%RESTVAR% %1转移转到循环 1:after_loop回声%RESTVAR%

如果有帮助,请告诉我!

Duplicate:

Clarification: I knew of the looping approach - this worked even before Command Extensions; I was hoping for something fun and undocumented like %~*1 or whatever - just like those documented at http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/percent.mspx?mfr=true.


In a Windows batch file (with the so called "Command Extensions" on), %1 is the first argument, %2 is the second, etc. %* is all arguments concatenated.

My question: is there a way to get everything AFTER %2, for example?

I couldn't find such a thing, and it would be helpful for something I'm working on.

解决方案

I am not sure if there is a direct command but you can always use a simple loop and shift to get the result in a variable. Something like:

@echo off
set RESTVAR=
shift
:loop1
if "%1"=="" goto after_loop
set RESTVAR=%RESTVAR% %1
shift
goto loop1

:after_loop
echo %RESTVAR%

Let me know if it helps!

这篇关于批处理参数:%1 之后的所有内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆