求问大佬,关于在shell脚本中的$*,$@和$#的一些问题!

#!/bin/bash 
my_fun() { 
echo "$#" 

echo 'the number of parameter in "$@" is '$(my_fun "$@") 
echo 'the number of parameter in "$*" is '$(my_fun "$*")
执行:./my.sh p1 "p2 p3" p4后返回:
the number of parameter in "$@" is 3
the number of parameter in "$*" is 1

$*表示所有这些参数都被双引号引住。若一个脚本接收两个参数,$*等于$1$2
$@表示所有这些参数都分别被双引号引住,若一个脚本接收到两个参数,$@等价于$1$2
$#表示提供给脚本的参数号

这里怎么看出$*和$@的区别呢?为什么执行结果是3和1呢?这里$#又是什么意思呢?

忽然笑
浏览 299回答 3
3回答

杨魅力

$* 这个程式的所有参数$# 这个程式的参数个数$@ 跟$*类似,但是可以当作数组用
打开App,查看更多内容
随时随地看视频慕课网APP