What is the history of $ {#} in bash

I ran into string length processing in bash 4.1.2 for two lines

At first: 1000000000000000000

developer@kernel ~> echo ${#1000000000000000000}
0
developer@kernel ~> s1=1000000000000000000
developer@kernel ~> echo ${#s1}
19

The second: 10000000000000000000

developer@kernel ~> echo ${#10000000000000000000}
19
developer@kernel ~> s2=10000000000000000000
developer@kernel ~> echo ${#s2}
20

How to explain strange behavior?

+4
source share
1 answer

${#var}usually is the length in characters ${var}. So ${#1000000000000000000}this is the argument length of 1000000000000000000th for the script. Since your script has not been called with so many arguments, this value is zero.

-, , , . ${#9223372036854775808}, 2 64.

+8

Source: https://habr.com/ru/post/1569011/


All Articles