Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bash scripting - writing an init.d script

Tags:

bash

init.d

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.

like image 257
user2759991 Avatar asked Dec 11 '25 05:12

user2759991


1 Answers

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).

like image 169
kojiro Avatar answered Dec 13 '25 01:12

kojiro



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!