Overview of Shell Startup Files


Contents

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

About this document

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


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. See the following:
AIX 3.2 APARs IX59863 and IX56867
AIX 4.1 APAR IX60035

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)

Restricted shell (Rsh)

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

Trusted shell (tsh)

tsh differs from Korn shell in the following ways:

Restricted Korn shell (ksh -r and rksh)

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://service.software.ibm.com/rs6k/fixdb.html


[ Doc Ref: 90605222214628     Publish Date: Dec. 18, 2001]