Skip to content

Environment

sarahmss edited this page Dec 11, 2021 · 3 revisions

For minishell project, we will be using a global structure containing our environment g_session, but what really is an environment?

What is the environment if not the shell?

To understand Unix behavior we can look at the syscalls (the basic API dor interacting with the kernel and OS) such as the exec family of calls. The initial argument for these functions is the name of a file that is to be executed.

  1. execle() and execvpe() functions allow the caller to specify the environment of the executed program via the argument envp (an array of pointers to null-terminated strings terminated by a NULL pointer).
  2. Other functions take the environment for the new process image from the external variable which works such as a global dictionary extern char **environ

Defining Environment variables

  • A variable is a container that has a defined value that can change.
  • They allow changing a part of the command that is to be executed.
  • Every shell has a set of attached variables
  • the Variable SHELL contains the path to the current shell. While Environment variables are 'global' and shared by all shells started AFTER variable is defined, Shell's variables are ONLY present in the shell in which they were defined. Since that, environment variables are inherited by child shells but shell variables are not.

Shell Parameter Expansion

The '$' character introduces parameter expansion, command substitution, or arithmetic expansion.

Associated builtins

  • env: Exhibits all the environment variables.
  • export: This allows you to configure and share environment variables between different programs and libraries accessed from the same terminal.
  • unset: Delete values of environment variables.

Clone this wiki locally