bash 在bash脚本中以英文格式获取日期月份
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29388671/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Getting date month in english format inside bash script
提问by dac777
In a bash script I have the following:
在 bash 脚本中,我有以下内容:
MES=$(date +"%b")
How can I get the month in english format?
Now if I echo $MES variable, I get abr. But I would like to get apr.
我怎样才能得到英文格式的月份?
现在,如果我回显 $MES 变量,我会得到 abr。但我想得到四月。
I'm trying to solve this without using if statement or switch. May be is an option...
I have tried date -u
but is not working for me.
我试图在不使用 if 语句或 switch 的情况下解决这个问题。可能是一种选择......
我已经尝试过date -u
但对我不起作用。
EDIT:
Finally I have put this line in the first line of script script:
编辑:
最后我把这一行放在脚本脚本的第一行:
#!/bin/bash
LANG=en_us_8859_1
# Here rest of the script
Now is working, but I can't accept my own answer as valid... I think because I haven't enough reputation in stackoverflow
现在正在工作,但我不能接受我自己的答案是有效的......我想是因为我在 stackoverflow 中没有足够的声誉
回答by jschnasse
Use
用
MES=$(LANG=en_us_88591; date +"%b")
MES=$(LANG=en_us_88591; date +"%b")
to change the language just for this single call.
只为这次通话更改语言。