覆盖bash脚本中的LANG变量

时间:2021-05-09 01:47:04

I'm running a script that contains the LANG variable set to 'french', when i run it manually with

当我手动运行时,我正在运行一个包含LANG变量设置为'french'的脚本

$(pwd)/script_name

It works fine, for example, i see the "e'" translated properly, but when is run by a cronjob, It seems like the LANG variable is set to english_us, i see the 'e`' as '?'

它运行正常,例如,我看到“e”被正确翻译,但是当由cronjob运行时,似乎LANG变量设置为english_us,我将'e`'看作'?'

I have no idea why this happens,even when running from a cronjob, the script should set its LANG to french, as it does when i run it manually. Any advice?

我不知道为什么会发生这种情况,即使从cronjob运行,脚本也应该将LANG设置为法语,就像我手动运行时一样。任何建议?

2 个解决方案

#1


1  

You can set environment variables right on the command line within your crontab, like so:

您可以在crontab的命令行中设置环境变量,如下所示:

* * * * * LANG=french script_name

#2


0  

I needed to set the environment variable of the process running the script using "export" so it needed to be : export LANG=french, got this from https://superuser.com/a/153378/257000

我需要使用“export”设置运行脚本的进程的环境变量,因此需要:export LANG = french,从https://superuser.com/a/153378/257000获取

#1


1  

You can set environment variables right on the command line within your crontab, like so:

您可以在crontab的命令行中设置环境变量,如下所示:

* * * * * LANG=french script_name

#2


0  

I needed to set the environment variable of the process running the script using "export" so it needed to be : export LANG=french, got this from https://superuser.com/a/153378/257000

我需要使用“export”设置运行脚本的进程的环境变量,因此需要:export LANG = french,从https://superuser.com/a/153378/257000获取