I can\'t get printf
to print a variable with the %e descriptor in a bash script. It would just say
#!/bin/bash
a=14.9
printf %e 14.9;
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.
I bumped into this error and found this page. In my case, it was 100% pilot error.
month=2
printf "%02d" month
it should be
printf "%02d" "${month}"
or more simply
printf "%02d" $month
You could have a locale problem, and it wasn't expecting a period. Try:
LC_NUMERIC="en_US.UTF-8" printf %e 14.9