value too great for base

有个这样的脚本:

declare -a dic
dic=(
["0001"]="0"
["0002"]="1"
["0003"]="2"
["0004"]="3"
["0005"]="4"
["0006"]="5"
["0007"]="6"
["0008"]="7" # 报错 value too great for base
["0011"]="8" 
["0012"]="9"
["0014"]="10"
)
key=${host:17:4}  # 10
id=${dic[$key]}  # 

错误类型:
进制问题:
0开头的被默认为八进制了,所以08就是无效的八进制数!太奇葩了!!
加个 10#。bash真是够了,明明是字符串,却给你转成数字,谁写的语言,
站粗来!

改为:

declare -a dic
dic=(
["10#0001"]="0"
["10#0002"]="1"
["10#0003"]="2"
["10#0004"]="3"
["10#0005"]="4"
["10#0006"]="5"
["10#0007"]="6"
["10#0008"]="7"
["10#0011"]="8"
["10#0012"]="9"
["10#0014"]="10"
)
key=${host:17:4}
id=${dic[10#$key]}

你可能感兴趣的:(value too great for base)