Christopher
Stoll

Old-School UNIX Script: .profile

Many years ago I managed numerous SGI UNIX workstations of various vintages (Indigo, O2, Octane, Origin, etc.). I wanted to be at home when I logged into any of the machines, and the user home directory was on an NFS share my .profile was always available, but I had to deal with the various capabilities of each particular computer and the different ways in which I would log in. So, I created a .profile script that would add features as they were available. Below is that old login script.

#
# C.STOLL's .profile
# for /bin/sh & /bin/bash
#

umask 002

############################
# Set the default X server #
############################
if [ ${DISPLAY:-setdisplay} = setdisplay ]
then
    if [ ${REMOTEHOST:-islocal} != islocal ]
    then
        DISPLAY=${REMOTEHOST}:0
    else
        DISPLAY=:0
    fi
    export DISPLAY
fi

############################
# Custom Path Deffinitions #
############################
pathalreadydone=`echo "$PATH" | awk -F: '{
path = ENVIRON["PATH"]
ndirs = split(path, pathlist, ":")
for (i = 1; i <= ndirs; i++) {print pathlist[i]}
}' | grep '~'`
if [ "$pathalreadydone" = "" ]; then
PATH=$PATH~:
PATH=$PATH~/bin:
PATH=$PATH/xyzuser/root/bin:
PATH=$PATH/xyzuser/root/bin/updaters:
fi

###########################################################
# Add some "Linux" settings (make the console friendlier) #
###########################################################
if [ -e /usr/freeware/bin/ls ]; then
alias ls='/usr/freeware/bin/ls --color --classify --human-readable'
alias dir='/usr/freeware/bin/ls --color --classify --human-readable -l'
fi
if [ -e /usr/freeware/bin/mcedit ]; then
alias edt='/usr/freeware/bin/mcedit'
alias edit='/usr/freeware/bin/mcedit'
fi

#################
# Misc. Aliases #
#################
alias del='rm -i'
alias cls='clear'

############################################
# If it is available use BASH as my shell, #
# if not use /bin/sh                       #
############################################
if [ "$SHELL" != '/bin/bash' ];
then
# This runs when we first login.
# It switches us to bash, if it exists.
if [ -e /bin/bash ];
then
SHELL=/bin/bash
/bin/bash
exit
else
echo ""
echo "/bin/bash not found."
echo "Using $SHELL"
echo ""
fi
else
# This runs only when we switch to bash.
# These niceties only work with bash.
if [ -e ~/bin/quote ];
then
# Print my login quote.
~/bin/quote
echo ""
else
echo "Quote program, ~/bin/quote, missing"
fi
# Set my prompt and titlebar message.
# Titlebar: \h=hostname =time(24hr) \w=pwd
# Prompt: \u=username \h=host
PS1="\[]0c\u@\h.na.xyz.com < > \w\]\u@\h>"
fi

Published: 2011-05-13
UNIXScriptOld-SchoolCode