Here is a nice ksh login profile I have written that switches you to bash.
It is very useful in environments where the system administrator has decided for you that you will use the korn shell, and has no interest in implementing your request for a different shell, one that makes you more productive, and in turn saves your employer or client money.
#!/bin/ksh
#-----------------------------------------------------------------------------#
#
# Workfile: $ RCSfile: $
# Date: $ Date: $
# Revision: $ Revision: $
# Tag/Label: $ Name: $
# SCCSID: @(#) $ Id: $
# Author: mike@archlug.org
#
# Description: ksh startup file
#
# Synopsis: .profile
#
# Options: None
#
# Operands: None
#
# Exit Status: 0 - Command completed successfully
# !0 - Command failed
#
# Notes: This file should be placed in the user HOME directory
#
# Copyright 2004 ArchLUG, Inc., Missouri, USA
# This work is licensed under the Creative Commons Attribution-ShareAlike License.
# To view a copy of this license, visit
# http://creativecommons.org/licenses/by-sa/1.0/
# or send a letter to
# Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
#
# Revision History is appended.
#
#-----------------------------------------------------------------------------#
version='$ Name: $'
#
# Switch out of ksh to bash
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
if [ -x /usr/bin/bash ]; then
if [ "X$SSH_TTY" != "X" ]; then
case "$0" in
*ksh) echo "Login under SSH detected. Switching to bash."
SHELL=/usr/bin/bash
export SHELL
exec /usr/bin/bash --login $*
;;
*) echo "SSH_TTY, not ksh: $*" ;;
esac
fi
case "$0" in
-*) echo "Login under ksh detected. Switching to bash."
SHELL=/usr/bin/bash
export SHELL
exec /usr/bin/bash --login $*
;;
*) if [ "X$SHLVL" = "X1" ]; then
echo "If you just issued a 'su' command,"
echo "You may want to 'source ~/.bash_profile'."
fi
;;
esac
fi
# --- FIN ---
#
#-----------------------------------------------------------------------------#
# Revision History:
# $ Log: $
#
#-----------------------------------------------------------------------------#
I also saw some thread on cygwin-app about issues when mangling with the MANPATH, PATH,
etc. variables.
Here's what I've done to alleviate the problem of every script tacking on another
copy of /usr/local/bin or whatever to PATH, but never checks to see if it is already
there, and sometimes even if the path being added exists.
So, I wrote some helper functions that will prepend or append a path to a variable.
It will do the right thing when the variable is empty, and won't insert directories
multiple times, and won't insert directories that don't exist. I usually have them in someplace like /etc/profile.functions and then just source it in. That way other scripts that play with paths can also use the functions.
It helps to preserve the existing path, setup your own, and then go back and re-add all of the paths in the original path variable. This way, any "extras" get included, but you get to determine the ordering, and eliminate duplicates.
I've created similar functions to remove paths (in case there are multiple entries for the same directory that should be removed).
Here's an example of how you might use such code to reconstruct the PATH in a script such
as [/etc/profile] or your [.profile] or .bash_profile:
# Save our original PATH
OPATH=$PATH
#
# Build a new PATH
PATH=""
addpath /some/path
:
# Add in all you want.
#
# When you are done, add in pre-existing PATH
oifs="$IFS"
IFS=:
for opath in $OPATH
do
addpath $opath
done
IFS=$oifs
unset oifs opath
And here's my code for the helper functions for the PATH variable:
addpath()
addpath() {
if [ -d "$1" ]; then
if [ "X$PATH" = "X" ]; then
PATH=$1
else
local existing=/usr/bin/true
local oifs="$IFS"
IFS=:
local opath
for opath in $PATH
do
[ "X$opath" = "X$1" ] && existing=/usr/bin/false
done
IFS=$oifs
$existing && PATH=${PATH}:$1
fi
export PATH
fi
}
prepath()
prepath() {
if [ -d "$1" ]; then
if [ "X$PATH" = "X" ]; then
PATH=$1
else
local existing=/usr/bin/true
local oifs="$IFS"
IFS=:
local opath
for opath in $PATH
do
[ "X$opath" = "X$1" ] && existing=/usr/bin/false
done
IFS=$oifs
$existing && PATH=$1:$PATH
fi
export PATH
fi
}
rmpath()
rmpath() {
local found
found=`echo "$PATH" | grep -i "$1"`
if [ "$found" ]; then
local oifs="$IFS"
IFS=:
local opath
local npath
for opath in $PATH
do
found=`echo "$opath" | grep -v -i "$1"`
[ "$found" ] && npath="${npath}:${opath}"
done
IFS=$oifs
PATH=$npath
export PATH
fi
}
Just create the related functions for MANPATH, LD_LIBRARY_PATH, and any other list-of-directories type of variable, and you're done.
I just haven't gotten around to writing a function factory for this, so that you can create these functions on-the-fly for any variable. If someone wants to post such functions here, just edit the page.
-- Mike
Here is a nice bash profile I wrote:
#!/usr/bin/bash
#-----------------------------------------------------------------------------#
#
# Workfile: $ RCSfile: $
# Date: $ Date: $
# Revision: $ Revision: 1.1 $
# Tag/Label: $ Name: $
# SCCSID: @(#) $ Id: $
# Author: mike@archlug.org
#
# Description: bash startup file
#
# Synopsis: .bash_profile
#
# Options: None
#
# Operands: None
#
# Exit Status: 0 - Command completed successfully
# !0 - Command failed
#
# Notes: This file should be placed in the user HOME directory
#
# Copyright 2004 ArchLUG, Inc., Missouri, USA
# This work is licensed under the Creative Commons Attribution-ShareAlike License.
# To view a copy of this license, visit
# http://creativecommons.org/licenses/by-sa/1.0/
# or send a letter to
# Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
#
#-----------------------------------------------------------------------------#
version='$ Name: $'
#
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Guarantee our HOSTNAME
if [ "X$HOSTNAME" = "X" ]; then
HOSTNAME=`uname -n`
export HOSTNAME
fi
# Guarantee our LOGNAME
if [ "X$LOGNAME" = "X" ]; then
if [ "X$USERNAME" = "X" ]; then
USER=`whoami`
USERNAME=$USER
export USER USERNAME
fi
LOGNAME=$USERNAME
export LOGNAME
fi
#
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Allow group access by default
umask 002
#
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Setup for a PC keyboard
tty=`tty`
if [ "X$tty" != "Xnot a tty" ]; then
stty istrip
stty erase '^H'
stty intr '^C'
fi
unset tty
#
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Run all of the profile.d scripts
# Note that these are supplied by separate packages
if [ -d "$HOME/profile.d" ]; then
for f in $HOME/profile.d/*
do
[ -f "$f" ] && . "$f"
done
unset f
fi
#
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Run our host-specific bash_profile
[ -f $HOME/.bash_profile.$HOSTNAME ] && . $HOME/.bash_profile.$HOSTNAME
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Run our user-specific bash_profile
[ -f $HOME/.bash_profile.$LOGNAME ] && . $HOME/.bash_profile.$LOGNAME
#
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Make sure these are exported
export PATH MANPATH LD_LIBRARY_PATH
#
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Setup aliases
[ -f /etc/bashrc ] && . /etc/bashrc
[ -f /etc/bash.bashrc ] && . /etc/bash.bashrc
[ -f $HOME/.bashrc ] && . $HOME/.bashrc
[ -f $HOME/.bashrc.$HOSTNAME ] && . $HOME/.bashrc.$HOSTNAME
[ -f $HOME/.bashrc.$LOGNAME ] && . $HOME/.bashrc.$LOGNAME
#
# Set your DISPLAY properly on Cygwin
ssh_from=`echo $SSH_CLIENT | /usr/bin/cut -d' ' -f1`
if [ "X$ssh_from" = "X127.0.0.1" ]; then
if [ "X$DISPLAY" = "X" ]; then
DISPLAY="localhost:0"
export DISPLAY
if [ "X$OSTYPE" = "Xcygwin" ]; then
xauth add `echo "${DISPLAY}" | sed 's/.*\(:.*\)/\1/'` . `/usr/bin/mcookie`
fi
fi
fi
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Setup for remote X sessions via sudo
if [ "X$TERM" = "Xxterm" ]; then
if [ "X$DISPLAY" = "X" ]; then
/usr/bin/echo "Enter DISPLAY [localhost:10]:\c"
read DISPLAY ; export DISPLAY
DISPLAY=${DISPLAY:-localhost:10}
else
echo "DISPLAY=$DISPLAY"
fi
disp=`echo $DISPLAY | cut -d ':' -f 2`
uid=`who am i | cut -d ' ' -f 1`
home=`grep $uid /etc/passwd | head -1 | cut -d ':' -f 6`
xauth=$XAUTHORITY
[ "X$xauth" = "X" ] && xauth=$home/.Xauthority
if [ -f $xauth ]; then
xauth -i -q -f $xauth extract - :$disp 2>/dev/null | xauth merge -
euid=`whoami`
[ "X$uid" = "X$euid" ] && chmod +r $xauth
fi
unset disp uid euid home xauth
stty erase '^?'
fi
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Cleanup functions
unset addpath prepath addmanpath premanpath addlibpath prelibpath
unset delpath delmanpath dellibpath
unset version
# --- FIN ---
#
#-----------------------------------------------------------------------------#