2

Bash manual says

When a program is invoked it is given an array of strings called the environment. This is a list of name-value pairs, of the form name=value.

  1. What are the relation and difference between the environment given to a program and the execution environment in which the program is invoked?

    Is the environment given to a program

    • the same concept as the execution environment in which the program is invoked?
    • part of the execution environment in which the program is invoked?
  2. Does the environment given to a program consist
    • only of all the environment variables of the program, each environment variable for a (name, value) pair?
    • or more than the environment variables of the program?
1

The Command Execution Environment includes "the environment". The bash manual refers to it as shell parameters that are set by variable assignment. Those "parameters" comprise the name-value pairs that are usually referred to as "the environment". You may find the environ(7) manpage useful for further information.

Besides the environment, the Command Execution Environment includes the context in which the program is started, things like the current working directory and uid that owns the process.

I hope that clears it up somewhat for you. If you want to know more, you need to better understand what bash is doing at the system level, particularly process control. You could start with e.g. fork(2) and following the SEE ALSO references, but the subject can't really be learned by reading the man pages. You need a book to explain how all the pieces fit together.

  • Thanks. What books do you recommend? – Tim Feb 17 '16 at 3:23
  • I'll mention two, although whether or not to recommend them depends on what you want to know. :-) McKusick's books, either about 4.4 BSD or FreeBSD, would be a good place to start. You'll find a sample chapter at freebsd.org/doc/en/books/design-44bsd/…. Excruciating detail can be found at the C programming level. The best modern one I know is The Linux Programming Interface by Michael Kerrisk, man7.org/tlpi, – James K. Lowden Feb 18 '16 at 18:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.