什么是" $#"特殊参数在bash是什么意思? [英] What does the "$#" special parameter mean in bash?

查看:295
本文介绍了什么是" $#"特殊参数在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

这篇关于什么是" $#"特殊参数在bash是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆