本文介绍了Unix $#命令有什么作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我阅读了此页面什么是特殊的美元符号外壳变量?,但我仍然不明白 $#
的作用.
I read this page What are the special dollar sign shell variables? but I still don't get what $#
does.
我有一个演讲幻灯片的例子:
I have an example from a lecture slide:
#!/bin/sh
echo Total no. of inputs: $#
echo first: $1
echo second: $2
我假设$#接受所有输入作为参数,我们应该期望有两个输入.那是在做什么吗?
I assume $# takes in all inputs as the argument, and we should expect two inputs. Is that what it's doing?
推荐答案
正如您的脚本所说:您要传递给脚本的命令行参数总数.
as your script says: Its total number of command line arguments you are passing to your script.
如果您的脚本名称为: kl.sh
if you have a script name as: kl.sh
执行为
./kl.sh hj jl lk
甚至 bash kl.sh hj jl lk
在脚本中您正在做
echo $#
它将打印 3
其中
$1 is hj
$2 is jl
$3 is lk
This tutorial will surely help you
这篇关于Unix $#命令有什么作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!