# Environment Variables¶

When a parent process creates a child process, the first transfers to the second a certain number of variables called environment variables. This allows the parent to pass values that will be known by the child process.

To know all the environment variables known by the current process, we can use the command env. A number of these variables are of great importance for the operation of the command interpreter:

To create an environment variable, simply use the command export.

# without export
i=toto
cat > f << END
#!/bin/bash
export PATH=$PATH:. which f f  The command which gives the path of the command (i.e., where it is located). which tar  If a command is located in different directories, the first occurence in PATH is executed. The -a option of the which command displays all locations in PATH of a given command. ### LD_LIBRARY_PATH¶ In a similar manner as PATH, LD_LIBRARY_PATH contains the directories where to find software libraries. This is important for compiled programs that make use of shared libraries. The ldd command lists for a given compiled program the set of shared libraries that are required by the program to run. In case of a missing software library, a command cannot be executed. By changing the LD_LIBRARY_PATH variable, path(s) to missing libraries can be added accordingly. which ls ldd /bin/ls  ###$¶

Every process is identified by a unique PID number (Process IDentifier).

This PID number can be obtained by the variable $. echo$$ ### #, @, 1, 2, 3, ...¶ A shell script can accept arguments. They are placed in a list of arguments accessible by variables. variable meaning $# number of arguments of the script
$@ all arguments $0 script name
$1 first argument of the script $2 second argument of the script
$n N-th argument of the script The shift command is used to decrement from 1 the list of arguments of a script. #!/bin/bash echo first argument:$1
echo second argument: $2 echo third argument:$3
echo shift
shift
echo first argument: $1 echo second argument:$2

# script use:
./script.sh a1 a2 a3