0

Does date +%a output always the weekday in the system language?

No matter if in bash, sh or cronjob

2 Answers 2

1

Yes, except it's not "system language" in general, but specifically the value of LANG or LC_TIME environment variables. Now, whether those variables are set or not may indeed depend on how the script is started.

For example, in some Linux distributions, the locale environment is set through pam_env and will be present everywhere – local, SSH, cron, etc. But in some other distributions, the environment is set through /etc/profile which only applies to interactive sh/bash logins but not batch ones.

The most reliable option is to specify the desired locale directly within your script.

For example, if you run env LC_TIME=en_US.UTF-8 date +%a then you will always get English output, no matter what the global system language is. And if you run env LC_TIME=de_DE.UTF-8 date +%a then the output will be in German, and so on.

(All locale-related functions first look at LC_something, e.g. LC_TIME or LC_MESSAGES, and if that's not set, they look at the general LANG.)

Note that the locale has to be made available system-wide first, using locale-gen or similar tools. Use locale -a to check which ones are currently available.

0

It's already specified in the man page

%a     locale's abbreviated weekday name (e.g., Sun)

So yes, the name is the locale's name

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .