[Solved] How do bash variable types work and how to work around automatic interpretation?


By doing ((aStr = $(printf %03d $a))), you are destroying again the careful formatting done by printf. You would see the same effect if you do a

(( x = 005 ))
echo $x

which outputs 5.

Actually the zeroes inserted by printf could do harm to your number, as you see by the following example:

(( x = 015 ))
echo $x

which outputs 13, because the ((....)) interprets the leading zero as an indication for octal numbers.

Hence, if you have a string representing a formatted (pretty-printed) number, don’t use this string in numeric context anymore.

2

solved How do bash variable types work and how to work around automatic interpretation?