我如何传递给一个Bash脚本参数的数目? [英] How do I find the number of arguments passed to a Bash script?

查看:211
本文介绍了我如何传递给一个Bash脚本参数的数目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何传递给一个Bash脚本参数的数目?

How do I find the number of arguments passed to a Bash script?

这是我目前:

#!/bin/bash
i=0
for var in "$@"
do
  i=i+1
done

这样做的还有其他(更好)的方式?

Are there other (better) ways of doing this?

推荐答案

的参数个数为 $#

搜索它这个网页上了解详情:
<一href=\"http://tldp.org/LDP/abs/html/internalvariables.html#ARGLIST\">http://tldp.org/LDP/abs/html/internalvariables.html#ARGLIST

Search for it on this page to learn more: http://tldp.org/LDP/abs/html/internalvariables.html#ARGLIST

这篇关于我如何传递给一个Bash脚本参数的数目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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