如何找到传递给 Bash 脚本的参数数量? [英] How do I find the number of arguments passed to a Bash script?
本文介绍了如何找到传递给 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?
推荐答案
参数个数为$#
在此页面上搜索以了解更多信息: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屋!
查看全文