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;
I know this is likely a very easy question, but I’m fairly new to bash and always used echo. Plus I couldn’t find an answer anywhere.
when run i get
$ ./test.text
./test.text: line 3: printf: 14.9: invalid number
0,000000
therefore my problem is the locale variable LC_NUMERIC: it is set so that i use commas as decimal separators. Indeed, it is set to an european localization:
$ locale | grep NUM
LC_NUMERIC="it_IT.UTF-8"
I thought I set it to en_US.UTF-8, but evidently I didn’t. Now the problem switches to find how to set my locale variable. Simply using
$ LC_NUMERIC="en_US.UTF-8"
won’t work.
This:
sets
$LC_NUMERIConly for the duration of that one command.This:
sets
$LC_NUMERIConly for the duration of the current shell process.If you add
to your
$HOME/.bashrcor$HOME/.bash_profile, it will set$LC_NUMERICfor all bash shells you launch.Look for existing code that sets
$LC_NUMERICin your.bashrcor other shell startup files.UPDATE:
If the
$LC_NUMERICenvironment variable is not set, theLC_NUMERIClocale setting can be set from the$LANGor$LC_ALL. Check your environment variable settings as well as the output of thelocalecommand.$LC_ALLoverrides$LC_NUMERIC, and$LC_NUMERICoverrides$LANG.man localeand/orman 7 localefor details.