什么是" $#"特殊参数在bash是什么意思?
问题描述:
香港专业教育学院遇到了code
Ive come across the code
if [ $# -eq 1 ]; then
echo "usage: Phar ~/flashmem ~/archive"
exit
fi
我从来没有碰到过[$#当量1];之前我似乎找到了意义
Ive never come across [ $# -eq 1 ]; before and I cant seem to find a meaning
答
在$#返回作为参数传递的参数个数
The "$#" return the number of parameters passed as argument
#!/bin/bash
echo $#
现在
./testess.sh test1 test2 test3
这回 3
./testess.sh test1 test2 test3 test4 test5
这回 5
因此,在您code如果$#等于一(只有一个参数传递)的数量,执行echo命令
So in your code if "$#" equal the number one (just one argument passed), execute the echo command