加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

linux – bash中“$#”是什么意思?

发布时间:2020-12-14 01:26:29 所属栏目:Linux 来源:网络整理
导读:参见英文答案 What does the “$#” special parameter mean in bash?????????????????????????????????????2个 我有一个脚本: login { # checking parameters - if not ok print error and exit script if [ $# -lt 2 ] || [ $1 == '' ] || [ $2 == '' ];
参见英文答案 > What does the “$#” special parameter mean in bash?????????????????????????????????????2个
我有一个脚本:

login {
    # checking parameters -> if not ok print error and exit script
    if [ $# -lt 2 ] || [ $1 == '' ] || [ $2 == '' ]; then
        echo "Please check the needed options (username and password)"
        echo ""
        echo "For further Information see Section 13"
        echo ""
        echo "Press any key to exit"
        read
        exit
    fi

  } # /login

但我真的不知道$#在第三行意味着什么.

解决方法

英镑符号很重要.

>如果它只是$#,那就是位置参数的数量,比如1美元,2美元,3美元. (请注意,不计算0美元.)>如果是${#var},则它是参数扩展中的字符数. (字符串长度)>如果是${#var [@]},那就是数组中元素的数量.由于bash数组是稀疏的,因此它可能与最后一个元素的索引加一.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读