I know $#
is the number of positional parameters in bash
. But how does bash
interpret ${##}
? Here, is a sample output from my system.
$ echo $#
0
$ echo ${#}
0
$ echo ${##}
1
$ echo $##
0#
$#
is the number of positional parameters, and ${##}
is the length of $#
's value in characters; in other words it's the base 10 logarithm plus one, rounded down, of the number of positional parameters. $##
doesn't work because it doesn't comply with the parameter expansion syntax.
Observe:
$ bash -c 'echo "$# ${##}"' _ {1..9}
9 1
$ bash -c 'echo "$# ${##}"' _ {1..10}
10 2
$ bash -c 'echo "$# ${##}"' _ {1..100}
100 3
See Bash Reference Manual § 3.5.3 Shell Parameter Expansion for further information.
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加