简体   繁体   中英

What does ${##} mean in bash?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM