printf command inside a script returns "invalid number" printf command inside a script returns "invalid number" bash bash

printf command inside a script returns "invalid number"


This:

LC_NUMERIC="en_US.UTF-8" printf %e 14.9

sets $LC_NUMERIC only for the duration of that one command.

This:

export LC_NUMERIC="en_US.UTF-8"

sets $LC_NUMERIC only for the duration of the current shell process.

If you add

export LC_NUMERIC="en_US.UTF-8"

to your $HOME/.bashrc or $HOME/.bash_profile, it will set $LC_NUMERIC for all bash shells you launch.

Look for existing code that sets $LC_NUMERIC in your .bashrc or other shell startup files.


You could have a locale problem, and it wasn't expecting a period. Try:

LC_NUMERIC="en_US.UTF-8" printf %e 14.9


I bumped into this error and found this page. In my case, it was 100% pilot error.

month=2printf "%02d" month

it should be

printf "%02d" "${month}"

or more simply

printf "%02d" $month