是否有一种方法来指示批处理文件中的最后n个参数? [英] Is there a way to indicate the last n parameters in a batch file?

查看:171
本文介绍了是否有一种方法来指示批处理文件中的最后n个参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在下面的示例中,我想从父批处理文件调用子批处理文件,并将所有剩余的参数传递给子进程。

In the following example, I want to call a child batch file from a parent batch file and pass all of the remaining parameters to the child.

C:\> parent.cmd child1 foo bar
C:\> parent.cmd child2 baz zoop
C:\> parent.cmd child3 a b c d e f g h i j k l m n o p q r s t u v w x y z

在parent.cmd内,我需要删除%1参数,并且只将剩余的参数传递给子脚本。

Inside parent.cmd, I need to strip %1 off the list of parameters and only pass the remaining parameters to the child script.

set CMD=%1
%CMD% <WHAT DO I PUT HERE>

我使用SHIFT和%*进行了调查,但是不行。虽然SHIFT会将位置参数向下移动1,但%*仍指原始参数。

I've investigated using SHIFT with %*, but that doesn't work. While SHIFT will move the positional parameters down by 1, %* still refers to the original parameters.

任何人都有任何想法?我应该放弃并安装Linux吗?

Anyone have any ideas? Should I just give up and install Linux?

推荐答案

%* 总是扩大到所有的原始参数,可悲的是。但是你可以使用下面的代码片段来构建一个包含第一个参数的变量:

%* will always expand to all original parameters, sadly. But you can use the following snippet of code to build a variable containing all but the first parameter:

rem throw the first parameter away
shift
set params=%1
:loop
shift
if [%1]==[] goto afterloop
set params=%params% %1
goto loop
:afterloop

,虽然...我不经常写这样的事情:)

I think it can be done shorter, though ... I don't write these sort of things very often :)

但应该工作。

这篇关于是否有一种方法来指示批处理文件中的最后n个参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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