19

From System-wide environment variables:

  • /etc/environment - This file is specifically meant for system-wide environment variable settings. It is not a script file, but rather consists of assignment expressions, one per line. Specifically, this file stores the system-wide locale and path settings.

I'm looking for an ABNF and/or a more detailed description of behaviour, or anything that isn't forum hearsay really.

If it's on Google, it's eluding me.

2 Answers 2

16

I'm not sure why this isn't made more clear, but /etc/environment isn't parsed by any single bit of code or any particular shell (or necessarily any shell at all) (try grep -r "/etc/environment" /etc and you'll see what I mean). pam in particular parses it directly, not putting it through a shell.

By convention, and I do mean convention, it's pure key-value pairs, with values optionally quoted. You can't put anything that tries to do e.g. variable expansion or command execution in there and expect it to work.

I'd be surprised if you can find a strict, formal grammar definition anywhere.

Probably the closest to an authoritative answer you can come is the pam_env docs: http://www.linux-pam.org/Linux-PAM-html/sag-pam_env.html

1
  • That's what "it is not a script file" is supposed to mean. But I guess a lot of people don't realise.
    – OrangeDog
    Commented Jun 18, 2018 at 12:06
3

You can find good information in the environ man page. It is accessible from a terminal, by typing man 7 environ in it.

By convention the strings in environ have the form "name=value".

You can also read it from your browser: http://manpages.ubuntu.com/manpages/lucid/en/man7/environ.7.html#toptoc2

And it gives you some examples of usage and more details.

1
  • 2
    Note that the environ(7) man page documents the format of the environment of a process, in the C API. The file /etc/environment is used to fill the environment of a process, but it has its own syntactic rules, as explained by Nicholas. Commented Aug 13, 2010 at 8:24

You must log in to answer this question.

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