IBM Support

Overview of Shell Startup Files

Question & Answer


Question

Overview of Shell Startup Files

Answer

This document gives an overview of shell startup files. This document is applicable to AIX Versions 4 and above.

Execution sequences at login
Sample startup files
Shell feature comparisons
Other shells provided with the base operating system
Recommended fixes

Execution sequences at login

At login, the shell defines the user environment after reading the shell startup files. The characteristics of the user environment are defined by the values given to the environment variables. This environment is maintained until the user logs off the system.

Login execution sequences:

The /etc/environment and /etc/security/environ files are executed regardless of what shell is run.

Even shells started by rexedc and rshd should set all the environment varibles that are defined in the /etc/environment file.

The /etc/environment file sets up the user environment such as the minimal search path, time zone, language etc. This file is not a shell script and does not accept data in a format other than the

    Name=<Value> 

format. This file is executed by all processes started by the init process and it affects all login shells.

The /etc/security/environ file is an ASCII file that contains stanzas with the environment attributes for individual users. Each stanza is identified by a user name and contains attributes in the

    Attribute=<Value> 

format. Each user stanza can have the following attributes:

usrenv
Defines environment variables (separated by commas) to be placed in the user environment at login.
sysenv
Defines environment variables to be placed in the user protected state environment at login. These variables are protected from access by unprivileged programs.
    Korn shell             C Shell                Bourne Shell 
    /etc/environment       /etc/environment       /etc/environment 
    /etc/security/environ  /etc/security/environ  /etc/security/environ 
    /etc/profile           /etc/csh.cshrc         /etc/profile 
                           /etc/csh.login 
    $HOME/.profile         $HOME/.cshrc           $HOME/.profile 
    $HOME/.kshrc           $HOME/.login 

NOTE: $HOME/.login and /etc/csh.login (csh) and $HOME/.profile and /etc/profile (ksh and bsh) get executed only at login. /etc/.cshrc and $HOME/.cshrc (csh) and $HOME/.kshrc (ksh) get executed every time a subshell is invoked. They are generally used to define aliases and shell variables (for example, noclobber, ignoreeof). It is recommended that you only use shell built-in commands in these files because using other commands could increase the startup time for shell scripts.


Sample startup files

Shell startup files define search paths, set informative shell prompts, set history files (csh and ksh only), and set terminal types.

    #!/bin/csh 
    ###################### 
    #SAMPLE .login file  # 
    ###################### 
    #define search path 
    set path=(/bin /usr/bin $HOME/bin /etc .) 
    #set prompt to reflect the current working directory 
    alias cd 'chdir \!* > /dev/null; set prompt="$cwd %"' 
    #set up history file 
    set history=20 
    #set up terminal type 
    eval `tset -s -Q -m ':?ibm3151'` 
    #-s flag prompts the C shell setenv process. 
    #The above line prompts users to set 
    #the TERM environment variable, 
    #hitting enter will set TERM to ibm3151 
    #!/bin/ksh 
    ####################### 
    #SAMPLE .profile file # 
    ####################### 
    #define search path 
    PATH=/bin:/usr/bin:$HOME/bin:/etc:. 
    #set prompt to refect the current working directory 
    PS1='$PWD $' 
    # To include variables LOGNAME and HOSTNAME to the PS1 
    # variable - set PS1 as follows 
    # PS1='${LOGNAME} @${HOSTNAME} ${PWD} $' 
    #set up history file 
    HISTFILE=$HOME/.my_history #default is $HOME/.sh_history 
    HISTSIZE=20 
    #set up terminal type 
    TERM=`termdef` 
    export PATH, PS1, TERM 

NOTE: Setting the bsh prompt to include the current working directory is slightly more complicated because Bourne shell does not have the PWD variable, but you can use the pwd command to build your own function. For example, put the following in the .profile:

    xcd () { cd $*; PS1="`pwd` $"; } 

and use xcd instead of cd to move around.


Shell feature comparisons

    Feature                 bsh        csh        ksh 
    compatible with bsh     n/a        no         yes 
    job control             yes        yes        yes 
    command history         no         yes        yes 
    command line editing    no         yes        yes 
    aliases                 no         yes        yes 
    noclobber 
    (protecting files been 
    overwritten)            no         yes        yes 
    ignoreeof 
    (ignore control-D)      no         yes        yes 
    logout file             no         yes        no 

Other shells provided with the base operating system

Default shell (sh)

  • the default shell, /usr/bin/sh (or /bin/sh), is linked to ksh in AIX Version 4

Restricted shell (Rsh)

Rsh is identical to bsh, except that the following are NOT allowed:

  • changing directory (with cd command)
  • setting the value of PATH or SHELL
  • specifying path or command names containing "/"
  • redirecting output

Trusted shell (tsh)

tsh differs from Korn shell in the following ways:

  • the function and alias definitions are not supported
  • the IFS and PATH environment variables CANNOT be redefined
  • only trusted programs can be run from tsh shell
  • command history is not supported
  • the only profile file used is /etc/tsh_profile

Restricted Korn shell (ksh -r and rksh)

  • cannot change the current directory
  • cannot change the value of the SHELL, ENV, or PATH variables
  • cannot invoke a program by specifying the explicit pathname of that program
  • cannot redirect output with >, >|, <>, >>

However, if a user working in a restricted Korn shell invokes a Korn shell script, then the script will run normally. That is, a restricted Korn shell does not restrict Korn shell scripts.

There are two ways to create a restricted Korn shell. One way is to invoke the program named rksh. Another way is by setting the SHELL variable. This variable holds a pathname. If the first letter of the leafname of this pathname contains the letter r, then the system invokes a restricted Korn Shell. Otherwise, the system invokes a regular Korn shell. For those unfamiliar with this term, the leafname of a pathname is the last (rightmost) component of the pathname.

For example, the following assignment in a startup script will cause the system to invoke a restricted Korn shell:

    SHELL=/usr/bin/rksh 

However, the following assignment in a startup script will cause the system to invoke a regular Korn shell:

    SHELL=/usr/bin/ksh 

Recommended fixes

bos.rte.shell delivers these shells. To search for the most current fixes to this fileset, go to the following URL and search on this fileset.

http://www-912.ibm.com/eserver/support/fixes/fcgui.jsp

[{"Product":{"code":"SWG10","label":"AIX"},"Business Unit":{"code":"BU058","label":"IBM Infrastructure w\/TPS"},"Component":"File management","Platform":[{"code":"PF002","label":"AIX"}],"Version":"5.3;5.2;5.1;4.3","Edition":"","Line of Business":{"code":"LOB08","label":"Cognitive Systems"}}]

Historical Number

isg1pTechnote0612

Document Information

Modified date:
17 June 2018

UID

isg3T1000361