批处理文件 - 一些命令行参数 [英] Batch files - number of command line arguments

查看:124
本文介绍了批处理文件 - 一些命令行参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

只是把一些shell脚本到批处理文件和有一件事我似乎无法找到...这是命令行参数的数量的简单计数。

Just converting some shell scripts into batch files and there is one thing I can't seem to find...and that is a simple count of the number of command line arguments.

如。如果您有:

myapp foo bar

在壳牌:


  • $# - > 2

  • $ * - >富栏

  • $ 0 - >的myapp <​​/ li>
  • $ 1 - >富

  • $ 2 - >栏

在批


  • ? ?! - > 2'; ----什么命令

  • %* - >富栏

  • %0 - >的myapp <​​/ li>
  • %1 - >富

  • 2% - >栏

所以,我环顾四周,无论是和我看在错误的地方或者我是盲人,但我似乎无法找到一种方式来获得的传入的命令行参数的个数计数。

So I've looked around, and either I'm looking in the wrong spot or I'm blind, but I can't seem to find a way to get a count of number of command line arguments passed in.

有没有类似shell的$#批处理文件?

Is there a command similar to shell's "$#" for batch files?

PS。我发现的最接近的是通过1秒%迭代,并使用'转移',但我需要在脚本中2等以后refernece%1%所以这是没有好。

ps. the closest i've found is to iterate through the %1s and use 'shift', but I need to refernece %1,%2 etc later in the script so that's no good.

推荐答案

谷歌上搜索了一下给你来自的维基

Googling a bit gives you the following result from wikibooks:

set argC=0
for %%x in (%*) do Set /A argC+=1

echo %argC%

好像cmd.exe的演变从旧的DOS时代了一下:)

Seems like cmd.exe has evolved a bit from the old DOS days :)

这篇关于批处理文件 - 一些命令行参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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