什么是$#构造在bash是什么意思? [英] What does the $# construct mean in bash?
本文介绍了什么是$#构造在bash是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我看
foo() {
if [[ $# -lt 1 ]]; then
return 0
fi
...
}
到底什么是它的比较通过使用$#因为它在那里?
What exactly is it comparing by using $# as it does there?
推荐答案
$#
重新presents的的的命令行参数号的传递到脚本。
$#
represents the number of command line arguments passed to the script.
sh-3.2$ cat a.sh
echo $# #print the number of cmd line args.
sh-3.2$ ./a.sh
0
sh-3.2$ ./a.sh foo
1
sh-3.2$ ./a.sh foo bar
2
sh-3.2$ ./a.sh foo bar baz
3
在函数内部(在你的情况下),用它重新presents的传递给函数的参数个数:
When used inside a function(as in your case) it represents the number of arguments passed to the function:
sh-3.2$ cat a.sh
foo() {
echo $# #print the number of arguments passed to the function.
}
foo 1
foo 1 2
foo 1 2 3
sh-3.2$ ./a.sh
1
2
3
这篇关于什么是$#构造在bash是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文