LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 892|回复: 6

${#*}

[复制链接]
发表于 2007-6-1 19:03:52 | 显示全部楼层 |阅读模式
各位:请解释一下。

${#*}

最好写一下例子。
发表于 2007-6-1 23:31:23 | 显示全部楼层
${#parameter}

The length in characters of the value of parameter is substituted.  If parameter is * or @, the value substituted is the number of positional parameters.  If parameter is an array name subscripted by * or @, the value substituted is the number of elements in the array.


具体作用,我不知道。
回复 支持 反对

使用道具 举报

发表于 2007-6-2 00:00:00 | 显示全部楼层
${#*}和${#@}表示位置参数的个数。比如脚本test_argument.sh的内容是
#! /bin/bash
echo "The number of arguments is ${#*}"
exit 0
运行这个脚本
$: sh test_argument.sh arg1 arg2 arg3
$: 3

${#array
  • }和${#array[@]}表示数组中元素的个数.
    比如脚本test_array.sh的内容是:
    #! /bin/bash
    declare -a array=(1 2 3 4)
    echo ${#array
  • }
    exit 0
    运行脚本结果是:
    4
  • 回复 支持 反对

    使用道具 举报

    发表于 2007-6-2 00:09:26 | 显示全部楼层
    ${#parameter}
    表示变量parameter的长度。in characters.比如para=wokaozheyexing,那${#para}=14

    If parameter is * or @, the value substituted is the number of positional parameters.
    就是${#*}或${#@}表示位置参数的个数

    If parameter is an array name subscripted by * or @, the value substituted is the number of elements in the array.
    如上上上上。。。。
    回复 支持 反对

    使用道具 举报

     楼主| 发表于 2007-6-2 10:05:23 | 显示全部楼层
    Post by BEINGJESSE
    ${#*}和${#@}表示位置参数的个数。比如脚本test_argument.sh的内容是
    #! /bin/bash
    echo "The number of arguments is ${#*}"
    exit 0
    运行这个脚本
    $: sh test_argument.sh arg1 arg2 arg3
    $: 3

    ${#array
  • }和${#array[@]}表示数组中元素的个数.
    比如脚本test_array.sh的内容是:
    #! /bin/bash
    declare -a array=(1 2 3 4)
    echo ${#array
  • }
    exit 0
    运行脚本结果是:
    4



  • 明白,太感谢了
    回复 支持 反对

    使用道具 举报

    发表于 2007-6-8 13:44:23 | 显示全部楼层
    谢谢谢谢谢谢
    回复 支持 反对

    使用道具 举报

    发表于 2007-6-8 18:50:08 | 显示全部楼层
    加深记忆了,谢谢
    回复 支持 反对

    使用道具 举报

    您需要登录后才可以回帖 登录 | 注册

    本版积分规则

    快速回复 返回顶部 返回列表