Softpanorama

Home Switchboard Unix Administration Red Hat TCP/IP Networks Neoliberalism Toxic Managers
May the source be with you, but remember the KISS principle ;-)
Bigger doesn't imply better. Bigger often is a sign of obesity, of lost control, of overcomplexity, of cancerous cells

AIX .profile and .ksrc files

News

See also

Redbooks IBM Links Recommended Links Bash and ksh93 Shell Prompts Customarization
Advanced Unix filesystem navigation Shell Command Line History Substitution Command completion Care and Feeding of Functions in Shell Readline and inputrc Ksh93
Shell profile and RC-files Pushd, popd and dirs cdpath Unix alias command and shell aliases Humor Etc

After bootup the AIX displays a login prompt on what looks like a character-based terminal, but which in reality is part of what is known as a high-function terminal (hft). An hft is not just a display; it also includes the keyboard, the mouse, dials, and keypad.

Logging in to the AIX, therefore, follows the typical UNIX login process: The getty process provides the login screen. If a user enters an id at this getty login prompt, getty starts the login process to validate the user. Like linux and Solaris AIX's login program checks not only /etc/passwd, which contains user names, but also a shadow password file, /etc/security/passwd, which contains the encrypted passwords of each of the users. login then starts a login shell as defined in /etc/passwd for the user, which by default is the KornShell (ksh). [ksh then reads the user's .profile. It is here in .profile that X Window can be started by calling the xinit command either directly or via the startx script.

The xinit command starts the X server and then reads the $HOME/.xinitrc file to determine which X programs to start. The three most likely applications to run from .xinitrc are

  1. An aixterm> (like xterm but emulating an hft display instead of a vt100),
  2. The AIX Windows desktop, an icon-based application and file management system,
  3. Motif Window Manager (mwm).

When a user exits his or her X Window session and logs out, control of the terminal returns to the init process, which spawns a new getty process, which in turn displays the Console Login on the display.

The following summarizes the AIX login process:

Other AIX login environments include xdm (X Display Manager), which provides an X Window login interface, and a ASCII-only display session. But the process described above is the most common.

Logout

If you are in an X Window session, stopping it by choosing End Session on the Root Menu will usually log you out. However, if your system displays an ASCII screen with a command line prompt (usually a "$" prompt) after you stop X, then you have to take the additional step of closing the shell by typing either the exit command or the logout commands.

The reason you might see a command line prompt after stopping the X server is because of the AIX concept of virtual terminals. The hft device is capable of supporting multiple screens on a single terminal. To create a virtual terminal you simply type the open command followed by the name of the program you want to run in the new virtual terminal. If you type open ksh, or if your .profile contains such a command, then you get a second screen running a KornShell. To access other screens, you simply type the CTRL+ALT/ACTION key sequence, and the terminal displays each screen one at a time.

If the X server is started by the open command, for example open xinit, it appears in its own screen. Thus ending the X Window session simply stops the X server in that particular screen and leaves other virtual terminals still running. To log out requires closing all virtual terminals, so whatever programs are running in them, be they shells or additional X servers, they must be closed in order to logout


Top Visited
Switchboard
Latest
Past week
Past month

NEWS CONTENTS

Old News ;-)

System Startup Files Overview

When you log in, the shell defines your user environment after reading the initialization files that you have set up. The characteristics of your user environment are defined by the values given to your environment variables. You maintain this environment until you log off the system.

The shell uses two types of profile files when you log in to the operating system. It evaluates the commands contained in the files and then executes the commands to set up your system environment. The files have similar functions except that the /etc/profile file controls profile variables for all users on a system whereas the .profile file allows you to customize your own environment.

The shell first evaluates the commands contained in the /etc/profile file and then runs the commands to set up your system environment in the /etc/environment file. After these files are run, the system then checks to see if you have a .profile file in your home directory. If the .profile file exists, it runs this file. The .profile file will specify if there also exists an environment file. If an environment file exists, (usually called .env), the system then runs this file and sets up your environment variables.

The /etc/profile, /etc/environment, and the .profile files are run once at login time. The .env file, on the other hand, is run every time you open a new shell or a window.

This section discusses the following initialization files:

/etc/profile File

The first file that the operating system uses at login time is the /etc/profile file. This file controls systemwide default variables such as:

The system administrator configures the profile file for all users on the system. Only the system administrator can change this file.

The following example is typical of an /etc/profile file:

#Set file creation mask
unmask 022
#Tell me when new mail arrives
MAIL=/usr/mail/$LOGNAME
#Add my /bin directory to the shell search sequence
PATH=/usr/bin:/usr/sbin:/etc::
#Set terminal type
TERM=lft
#Make some environment variables global
export MAIL PATH TERM

See .profile File Format in the AIX Version 4.3 Files Reference for detailed information about the /etc/profile file.

/etc/environment File

The second file that the operating system uses at login time is the /etc/environment file. The /etc/environment file contains variables specifying the basic environment for all processes. When a new process begins, the exec subroutine makes an array of strings available that have the form Name=Value. This array of strings is called the environment. Each name defined by one of the strings is called an environment variable or shell variable. The exec subroutine allows the entire environment to be set at one time.

When you log in, the system sets environment variables from the environment file before reading your login profile, .profile. The following variables make up the basic environment:

HOME The full path name of the user's login or HOME directory. The login program sets this to the name specified in the /etc/passwd file.
LANG The locale name currently in effect. The LANG variable is initially set in the /etc/profile file at installation time.
NLSPATH The full path name for message catalogs.
LOCPATH The full path name of the location of National Language Support tables.
PATH The sequence of directories that commands, such as sh, time, nice and nohup, search when looking for a command whose path name is incomplete.
TZ The time zone information. The TZ environment variable is initially set by the /etc/profile file, the system login profile.

See .environment File in the AIX Version 4.3 Files Reference for detailed information about the /etc/environment file.

.profile File

The third file that the operating system uses at login time is the .profile file. The .profile file is present in your home ($HOME) directory and enables you to customize your individual working environment. Because the .profile file is hidden, use the li -a command to list it.

After the login program adds the LOGNAME (login name) and HOME (login directory) variables to the environment, the commands in the $HOME/.profile file are executed if the file is present. The .profile file contains your individual profile that overrides the variables set in the /etc/profile file. The .profile file is often used to set exported environment variables and terminal modes. You can tailor your environment as desired by modifying the .profile file. Use the .profile file to control the following defaults:

The following example shows a typical .profile file:

PATH=/usr/bin:/etc:/home/bin1:/usr/lpp/tps4.0/user::
epath=/home/gsc/e3:
export PATH epath
csh

This example has defined two path variables (PATH and epath), exported them, and opened a C shell (csh).

You can also use the .profile file (or if it is not present, the /etc/profile file) to determine login shell variables. You can also customize other shell environments. For example, use the .cshrc file and .kshrc file to tailor a C shell and a Korn shell, respectively, when each type of shell is started.

.env File

A fourth file that the operating system uses at login time is the .env file, if your .profile has the following line: export ENV=$HOME/.env

The .env file enables you to customize your individual working environment variables. Because the .env file is hidden, use the li -a command to list it. The .env file contains the individual user environment variables that override the variables set in the /etc/environment file. You can tailor your environment variables as desired by modifying your .env file. The following example shows a typical .env file:

export  myid=`id | sed -n -e 's/).*$//' -e 's/^.*(//p'` 
export  bold=`tput smso` 
export  norm=`tput rmso`
#set prompt: login & system name (reverse video) & path (normal)
if [ $myid = root ]
        then    typeset -x PSCH='${bold}#:${norm}\${PWD}> '
                PS1="${bold}#:${norm}\${PWD}> "
        else    typeset -x PSCH='>'
                PS1="${bold}$LOGNAME@$UNAME:${norm}\${PWD}> "
                PS2=">"
                PS3="#?"
fi
export PS1 PS2 PS3
#setup my command aliases
alias   ls="/bin/ls -CF" \
        d="/bin/ls -Fal | pg" \
        rm="/bin/rm -i" \
        up="cd .."
Note: When modifying the .env file, ensure that newly created environment variables do not conflict with standard variables such as MAIL, PS1, PS2, and IFS.

pSeries and AIX Information Center

The following is a sample of a .kshrc script on one specific system. The contents of your .kshrc file can be significantly different.

# @(#).kshrc 1.0
# Base Korn Shell environment
# Approach:
#      shell            initializations go in ~/.kshrc
#      user             initializations go in ~/.profile
#      host / all_user  initializations go in /etc/profile
#      hard / software  initializations go in /etc/environment      
# DEBUG=y       # uncomment to report
[ "$DEBUG" ] && echo "Entering .kshrc"
set -o allexport
# options for all shells --------------------------------
# LIBPATH must be here because ksh is setuid, and LIBPATH is
# cleared when setuid programs are started, due to security hole.
LIBPATH=.:/local/lib:/lib:/usr/lib
# options for interactive shells follow-------------------------
TTY=$(tty|cut -f3-4 -d/)
HISTFILE=$HOME/.sh_hist$(echo ${TTY} | tr -d '/')
PWD=$(pwd)
PS1='${LOGNAME}@${HOSTNAME} on ${TTY}[${PWD}] '
# aliases
[ "$DEBUG" ] && echo "Setting aliases"
alias pg="pg -n -p':Page %d: '"
alias more="pg -n -p':Page %d: '"
alias cls="tput clear"
alias sane="stty sane"
alias rsz='eval $(resize)'
# mail check
if [ -s "$MAIL" ]       # This is at Shell startup.  In 
then echo"$MAILMSG"     # normal operation, the Shell checks
fi                      # periodically.
# aixterm window title

[[ "$TERM" = "aixterm" ]] && echo "\033]0;$USER@${HOSTNAME%t1}\007"
# functions
[ "$DEBUG" ] && echo "Setting functions"
function pid { ps -e | grep $@; }
function term {
  if [ $# -eq 1 ]
  then
    echo $TERM
    TERM=$1
    export TERM
  fi
  echo $TERM
}
function back {
  cd $OLDPWD
  echo $CWD $OLDPWD
}
[ "$DEBUG" ] && echo "Exiting .kshrc"
set +o allexport

Stupid Korn Shell Tricks

HOST=`hostname`
export PS1='^[[01;32m${USER}@^[[1;34m${HOST%%.*} ^[[01;36m${PWD##*/} $^[[0m '

HOST=`hostname`
export PS1='${USER}@${HOST} ${PWD} $ '

AIX's ksh

The ksh that ships with IBM's AIX lacks tab completion and history with arrow keys. As googling for the solutions indicates that a great many people have the same question, here are the quick and dirty answers.

One can choose to set -o emacs or set -o vi. Most bash users are familiar with what this means. The default bash (and many other shells) option is emacs mode, where simple command line editing is possible using emacs style keystrokes. Using vi mode uses vi style keystrokes. However, even many vi users use emacs mode for the command line.

With AIX, one has to set this, either on the command line or in your .profile. If you choose the emacs mode, command and filename completion is done with esc esc (in other words, hitting the escape key twice.) History is done with ctl+p and ctl+n, as in previous and next. Googling gives some keybindings you can add to use the arrow keys instead, but I never bothered.

If you are in vi mode then esc \ gives filename and command completion and history is done with esc k for the previous command. If you want to keep going back, after the first time, you can just hit k.

Anyway, these were the little things I had to look up to get my ksh working as I wanted it to work. Hopefully, some may find it of use.

How to make custom prompts

The Korn Shell:

The Korn shell does support colors. To color the prompt you will want to place this symbol in your prompt.$'\E[Xm'. Replace X with the number of the color you want. Example:

PS1=$'\E[31m'`logname`@`hostname -s`:$'\E[0m>' #Custom prompt settings.

PS1 = "red text whoami hostname normal display>"

So basically you have told the computer all text from here to be red. After that you have told the computer to place the hostname and whoami in the prompt. Now return the display to a normal setting. This is important because forgetting to tell it to go back to normal means everything will be red, or worse whatever your last color command is. The point being when you are done make sure you tell it to return to normal.
Okay more than one color:

PS1=$'\E[31m'`logname`@$'\E[1;33m'`hostname -s`:$'\E[0m>' #Custom prompt settings

PS1 = "red text whoami yellow text hostname normal display>

Okay background color:

PS1=$'\E[46;31m'`logname`@$'\E[1;33m'`hostname -s`:$'\E[0m>' #Custom prompt settings

PS1 ="Cyan background red text whoami yellow text hostname normal display>" You can have multiple colors in the brackets. Separate them with a semicolon. Also don't ask for two colors to cover the same text. Your computer will get mad at you.

Certain colors need a semicolon in order to appear. Yellow as the above example shows is 1;33 do not use just 33 or it will come out brown. If you have a 0;31 you don't need to place the 0.
These are just some of things you can do. Don't be afraid to experiment. Post your Korn shell prompt here.

Reference

Prompt

export myid=`id | sed -n -e 's/).*$//' -e 's/^.*(//p'`
export bold=`tput smso`
export norm=`tput rmso`
#set prompt: login & system name (reverse video) & path (normal)
if [ $myid = root ]
then typeset -x PSCH='${bold}#:${norm}\${PWD}> '
PS1="${bold}#:${norm}\${PWD}> "
else typeset -x PSCH='>'
PS1="${bold}$LOGNAME@$UNAME:${norm}\${PWD}> "
PS2=">"
PS3="#?"
fi
export PS1 PS2 PS3

.kshrc

# @(#).kshrc 1.0
# Base Korn Shell environment
# Approach:
#      shell            initializations go in ~/.kshrc
#      user             initializations go in ~/.profile
#      host / all_user  initializations go in /etc/profile
#      hard / software  initializations go in /etc/environment      
# DEBUG=y       # uncomment to report
[ "$DEBUG" ] && echo "Entering .kshrc"
set -o allexport
# options for all shells --------------------------------
# LIBPATH must be here because ksh is setuid, and LIBPATH is
# cleared when setuid programs are started, due to security hole.
LIBPATH=.:/local/lib:/lib:/usr/lib
# options for interactive shells follow-------------------------
TTY=$(tty|cut -f3-4 -d/)
HISTFILE=$HOME/.sh_hist$(echo ${TTY} | tr -d '/')
PWD=$(pwd)
PS1='${LOGNAME}@${HOSTNAME} on ${TTY}[${PWD}] '
# aliases
[ "$DEBUG" ] && echo "Setting aliases"
alias pg="pg -n -p':Page %d: '"
alias more="pg -n -p':Page %d: '"
alias cls="tput clear"
alias sane="stty sane"
alias rsz='eval $(resize)'
# mail check
if [ -s "$MAIL" ]       # This is at Shell startup.  In 
then echo"$MAILMSG"     # normal operation, the Shell checks
fi                      # periodically.
# aixterm window title

[[ "$TERM" = "aixterm" ]] && echo "\033]0;$USER@${HOSTNAME%t1}\007"
# functions
[ "$DEBUG" ] && echo "Setting functions"
function pid { ps -e | grep $@; }
function term {
  if [ $# -eq 1 ]
  then
    echo $TERM
    TERM=$1
    export TERM
  fi
  echo $TERM
}
[ "$DEBUG" ] && echo "Exiting .kshrc"
set +o allexport



Etc

Society

Groupthink : Two Party System as Polyarchy : Corruption of Regulators : Bureaucracies : Understanding Micromanagers and Control Freaks : Toxic Managers :   Harvard Mafia : Diplomatic Communication : Surviving a Bad Performance Review : Insufficient Retirement Funds as Immanent Problem of Neoliberal Regime : PseudoScience : Who Rules America : Neoliberalism  : The Iron Law of Oligarchy : Libertarian Philosophy

Quotes

War and Peace : Skeptical Finance : John Kenneth Galbraith :Talleyrand : Oscar Wilde : Otto Von Bismarck : Keynes : George Carlin : Skeptics : Propaganda  : SE quotes : Language Design and Programming Quotes : Random IT-related quotesSomerset Maugham : Marcus Aurelius : Kurt Vonnegut : Eric Hoffer : Winston Churchill : Napoleon Bonaparte : Ambrose BierceBernard Shaw : Mark Twain Quotes

Bulletin:

Vol 25, No.12 (December, 2013) Rational Fools vs. Efficient Crooks The efficient markets hypothesis : Political Skeptic Bulletin, 2013 : Unemployment Bulletin, 2010 :  Vol 23, No.10 (October, 2011) An observation about corporate security departments : Slightly Skeptical Euromaydan Chronicles, June 2014 : Greenspan legacy bulletin, 2008 : Vol 25, No.10 (October, 2013) Cryptolocker Trojan (Win32/Crilock.A) : Vol 25, No.08 (August, 2013) Cloud providers as intelligence collection hubs : Financial Humor Bulletin, 2010 : Inequality Bulletin, 2009 : Financial Humor Bulletin, 2008 : Copyleft Problems Bulletin, 2004 : Financial Humor Bulletin, 2011 : Energy Bulletin, 2010 : Malware Protection Bulletin, 2010 : Vol 26, No.1 (January, 2013) Object-Oriented Cult : Political Skeptic Bulletin, 2011 : Vol 23, No.11 (November, 2011) Softpanorama classification of sysadmin horror stories : Vol 25, No.05 (May, 2013) Corporate bullshit as a communication method  : Vol 25, No.06 (June, 2013) A Note on the Relationship of Brooks Law and Conway Law

History:

Fifty glorious years (1950-2000): the triumph of the US computer engineering : Donald Knuth : TAoCP and its Influence of Computer Science : Richard Stallman : Linus Torvalds  : Larry Wall  : John K. Ousterhout : CTSS : Multix OS Unix History : Unix shell history : VI editor : History of pipes concept : Solaris : MS DOSProgramming Languages History : PL/1 : Simula 67 : C : History of GCC developmentScripting Languages : Perl history   : OS History : Mail : DNS : SSH : CPU Instruction Sets : SPARC systems 1987-2006 : Norton Commander : Norton Utilities : Norton Ghost : Frontpage history : Malware Defense History : GNU Screen : OSS early history

Classic books:

The Peter Principle : Parkinson Law : 1984 : The Mythical Man-MonthHow to Solve It by George Polya : The Art of Computer Programming : The Elements of Programming Style : The Unix Haterís Handbook : The Jargon file : The True Believer : Programming Pearls : The Good Soldier Svejk : The Power Elite

Most popular humor pages:

Manifest of the Softpanorama IT Slacker Society : Ten Commandments of the IT Slackers Society : Computer Humor Collection : BSD Logo Story : The Cuckoo's Egg : IT Slang : C++ Humor : ARE YOU A BBS ADDICT? : The Perl Purity Test : Object oriented programmers of all nations : Financial Humor : Financial Humor Bulletin, 2008 : Financial Humor Bulletin, 2010 : The Most Comprehensive Collection of Editor-related Humor : Programming Language Humor : Goldman Sachs related humor : Greenspan humor : C Humor : Scripting Humor : Real Programmers Humor : Web Humor : GPL-related Humor : OFM Humor : Politically Incorrect Humor : IDS Humor : "Linux Sucks" Humor : Russian Musical Humor : Best Russian Programmer Humor : Microsoft plans to buy Catholic Church : Richard Stallman Related Humor : Admin Humor : Perl-related Humor : Linus Torvalds Related humor : PseudoScience Related Humor : Networking Humor : Shell Humor : Financial Humor Bulletin, 2011 : Financial Humor Bulletin, 2012 : Financial Humor Bulletin, 2013 : Java Humor : Software Engineering Humor : Sun Solaris Related Humor : Education Humor : IBM Humor : Assembler-related Humor : VIM Humor : Computer Viruses Humor : Bright tomorrow is rescheduled to a day after tomorrow : Classic Computer Humor

The Last but not Least Technology is dominated by two types of people: those who understand what they do not manage and those who manage what they do not understand ~Archibald Putt. Ph.D


Copyright © 1996-2018 by Dr. Nikolai Bezroukov. www.softpanorama.org was initially created as a service to the (now defunct) UN Sustainable Development Networking Programme (SDNP) in the author free time and without any remuneration. This document is an industrial compilation designed and created exclusively for educational use and is distributed under the Softpanorama Content License. Original materials copyright belong to respective owners. Quotes are made for educational purposes only in compliance with the fair use doctrine.

FAIR USE NOTICE This site contains copyrighted material the use of which has not always been specifically authorized by the copyright owner. We are making such material available to advance understanding of computer science, IT technology, economic, scientific, and social issues. We believe this constitutes a 'fair use' of any such copyrighted material as provided by section 107 of the US Copyright Law according to which such material can be distributed without profit exclusively for research and educational purposes.

This is a Spartan WHYFF (We Help You For Free) site written by people for whom English is not a native language. Grammar and spelling errors should be expected. The site contain some broken links as it develops like a living tree...

You can use PayPal to make a contribution, supporting development of this site and speed up access. In case softpanorama.org is down you can use the at softpanorama.info

Disclaimer:

The statements, views and opinions presented on this web page are those of the author (or referenced source) and are not endorsed by, nor do they necessarily reflect, the opinions of the author present and former employers, SDNP or any other organization the author may be associated with. We do not warrant the correctness of the information provided or its fitness for any purpose.

The site uses AdSense so you need to be aware of Google privacy policy. You you do not want to be tracked by Google please disable Javascript for this site. This site is perfectly usable without Javascript.

Last modified: November 04, 2017