Bash: Both date "%b" and date "%h" (and of course) date "%B" gives full name of month?
bash, linux, shell, ubuntu-12.04
Solution
I've tested it and the problem seems to be the norwegian localization:
$ LC_ALL=C date +%b
Apr
$ LC_ALL=nn_NO.UTF-8 date +%b
april
therefore when you try to parse the log file you should set the `LC_ALL` environment variable to `C`, i.e.
LC_ALL=C command
or
export LC_ALL=C
# your script code here
export -n LC_ALL
For more informations on locales setting see the Locale page on Ubuntu wiki.
Problem
I am writing a shell-script in Ubuntu server 12.04 which is supposed to compare some data in a log file. In the log file, the date is given in the format: ``` [Mon Apr 08 15:02:54 2013] ``` As you can see, it states Apr. According to the man-page, the option to be used in bash for this is b or h. However it doesn't matter wether I (in my comparing script, or directly in shell) use b, h or B. They all return the full name of the month. ``` date +"%b" #Returns april (should have returned Apr) date +"%h" #Returns april (should have returned Apr) date +"%B" #Returns april (correct? Should it not be capital A?) ``` This of course makes it very difficult to do comparisons based on the date... Has anyone else experienced this, and found a solution? (I'm not sure if this is relevant, but I chose Norwegian as installation language when I installed the server.) Thank's to the answer of @toro2k here, I ended up with a working solution: ``` DATE=`LC_ALL=C date +%b" "%d" "%H` ``` (This did not work: ``` LC_ALL=C ``` DATE=`date +%b" "%d" "%H` )