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.

UPDATE:

If the $LC_NUMERIC environment variable is not set, the LC_NUMERIC locale setting can be set from the $LANG or $LC_ALL. Check your environment variable settings as well as the output of the locale command. $LC_ALL overrides $LC_NUMERIC, and $LC_NUMERIC overrides $LANG. man locale and/or man 7 locale for details.


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

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

Tags:

Printf

Bash