質問

I'm using /etc/init.d/httpd as a template for an init.d script. I understand everything that is going on in the file except the following line:

LANG=$HTTPD_LANG daemon --pidfile=${pidfile} $httpd $OPTIONS

Can somebody explain why HTTPD_LANG (which is set to "C") should be in there before the daemon function? Thanks.

役に立ちましたか?

解決

When you assign an environment variable immediately before executing a command, the variable is effectively exported in the command's environment, but doesn't affect the parent environment. From man bash:

The environment for any simple command or function may be augmented temporarily by prefixing it with parameter assignments, as described above in PARAMETERS. These assignment statements affect only the environment seen by that command.

So what's happening in this initscript is that the LANG variable, set to whatever you've configured HTTPD_LANG to be (in this case "C"), is getting exported into the daemon command's environment (and presumably from there into the httpd's environment).

他のヒント

Anything that will not see user interaction is only going to be slowed down by "proper localization". Setting LANG="C" can give up to a 5X speed improvement according to Barry Kauler's tests.

You can get the same speedups by saving the LANG variable to a temp variable, running the critical program with LANG=C and then restoring LANG

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top