Artificial intelligent assistant

Add leading zeroes to a user's input but is being transformed with printf I am currently looking for an alternative to the following code that works a little less 'wonky'. printf "Please enter the ticket number:\t"; read vTICKET; vTICKET=$(printf %04d "$vTICKET"); printf "$vTICKET\n"; If I input `072` as the input, this is what I see Please enter the ticket number: 072 0058 I am wondering if there is another way I can be a little more forgiving on the input or with the `read` command? `printf` seemed like the cool way to add leading zeroes without actually testing string length.

The leading zeros on the input value are causing the shell to interpret it as an octal number.

You can force decimal conversion using `10#` e.g.


$ printf "Please enter the ticket number:\t"; read vTICKET; vTICKET=$(printf %04d "$((10#$vTICKET))" ); printf "$vTICKET\
";
Please enter the ticket number: 072
0072


Note that in bash, you can assign the results of a `printf` to a variable directly using `-v` e.g. `printf -v vTICKET %04d "$((10#$vTICKET))"`

See also How do I stop Bash from interpreting octal code instead of integer?

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy f5898ca329ad9be5056c9b8fbd33837d