Why did “09” 以及 “08” are invalid numbers, “07” 以及 “06” are fine
由于之前按<代码>0进行分类,是一种常规的简短含义: 序号为。
printf "%d
" 010 0100
8
64
printf "%o
" 8 64 0100
10
100
100
printf "%04o
" 8 64 0100
0010
0100
0100
How to work with this?
Using bash integer: preceding number by 10#
Under bash, you could precise by this way, which base is used for number
echo $(( 10#0100))
100
echo $(( 10#0900))
900
echo $(( 10#0900 ))
900
以及
echo $(( 8#100 ))
64
echo $(( 2#100 ))
4
当然!
There are only 10 types of people in the world: those who underst以及 binary, 以及 those who don t.
Using bash Parameter Expansion
为此,您必须使用一个变量。
a=09
echo ${a#0}
9
This will work fine until you just have only one 0
to drop.
a=0000090
echo ${a#*0}
000090
echo ${a##0}
000090
http://www.un.org/Depts/DGACM/index_french.htm
echo ${a##*(0)}
0000090
shopt -s extglob
echo ${a##*(0)}
90
Using floating point
with printf
printf "%.0f
" 09
9
我愿使用<代码>-v 备选办法> printf
,用于确定一些变量:
printf -v a %.0f 09
echo $a
9
or even if
a=00090
printf -v a %.0f $a
echo $a
90