Lesson 10: UNIX Shell Environment

  1. Objectives
  2. Shell Variables
  3. The Shell Environment

    When a shell forks a child, not all of the variables get passed on to the child. Only those variables that are in the shell’s environment are passed on to the child. To see the variables that are in the shell’s environment with the command: env To add a shell variable to the environment, use the export command: export PS1
  4. .bash_profile
    The .bash_profile is a shell script that sets up a user's shell environment. This script is executed each time the user logs in. The .bash_profile is used for initializing shell variables, running the user's .bashrc file, running basic commands like umask and set -o options.
  5. .bashrc
    The .bashrc is a shell script that is executed during user login and whenever a new shell is invoked. This file usually contains the user defined aliases. e.g.
        alias bye="clear;exit"
        alias rm="rm -i"
  6. The . and exec Commands
    In normal execution of a unix command, shell-script or binary, the child process in unable to affect the login shell environment. Sometimes it is desireable to run a shell script that will initialize or change shell variables in the parent environment. To do this, the shell (bash) provides a . (dot) or source command, which instructs the shell to execute the shell script itself, without spawning a child process to run the script.
    . shscript or
    source shscript
    In this example, the commands in the file shscript are run by the parent shell, and therefore, any changes made to the environment will last for the duration of the login session.
    If a UNIX command is run using the exec command, the shell will terminate upon the exiting of that command:
    exec clear
    This will have the effect of clearing the screen and logging off the computer.
     
  7. UNIX Printing
    Users have access to three print commands for viewiing the status of the print system, for printing a file to a particular printer, and for viewing and cancelling their print jobs.