[rescue] Solaris 10 puzzle

Sandwich Maker adh at an.bradford.ma.us
Mon Feb 21 19:43:54 CST 2005


" From: Mike Parson <mparson at bl.org>
" 
" 
" What's PS1 set to?
" 
" I've seen people that want the hostname in their prompt put something
" like `hostname -s` in PS1, but when the used sudo or su2, that suddenly
" got run as root and changed the hostname to -s.
" 
" At least with bash, there's a built-in sequence for getting the hostname
" in the prompt (\h), rather than running a command to stuff it in there,
" prevents such mistakes.

there's no need to run any command every prompt, in ksh anyway.  maybe
in csh but not in tcsh.

i run ksh, have since ksh86 was new.  in my .profile, i have:

############## .profile start ################
export HOSTNAME=$(hostname)
typeset -i _TITLE	# for hpterm PS1
typeset -r _DUMMY	# for hpterm PS1
############## .profile end ################

in my $ENV i have:

############## $ENV start ################
USER=$( PATH=/usr/bin:/usr/ucb whoami )

case $USER in
root)	SUF='#';;
*)	SUF=':';;
esac

case $TERM in
sun*)
	[ "$TTY" != /dev/console ] &&
	PS1=']L$HOSTNAME\\]l$USER@$HOSTNAME:$PWD\\
$BOLD!$SUF$SGR0 '
	;;
xterm|dtterm)
	PS1=']1;$HOSTNAME]2;$USER@$HOSTNAME:$PWD
$BOLD!$SUF$SGR0 '
	;;
hpterm)
	PS1='${_DUMMY[_TITLE=((${#USER}+${#HOSTNAME}+${#PWD}+2))]}&f-1k${#HOSTNAME}D$HOSTNAME
&f0k${_TITLE}D$USER@$HOSTNAME:$PWD
K$BOLD!$SUF$SGR0 '
	;;
esac

BOLD=$(tput bold) RMSO=$(tput rmso) SGR0=$(tput sgr0) SMUL=$(tput smul)
PS4='$BOLD${0##*/}$RMSO line $SMUL$LINENO$SGR0:	'
export PS1 PS4
############## $ENV end ################

it works on sunos [with ksh88], solaris, hp-ux 9 and 10, and sco
unixware 7.  i haven't tested it on aix or irix, but anything with
ksh88 or ksh93 [incl. dtksh] and a valid terminfo should work; red
hat linux comes with a default bash prompt that functions a -lot-
like this...

it puts the hostname in the icon label, and user at hostname:path in the
window titlebar.  it correctly works on cd, su, and rlogin etc.  uses
up otherwise wasted space, keeps my cmdline usage short.

hostname is only executed once, at login.  why every time you issue a
prompt?  it doesn't change.

likewise, user is only set when the shell starts up.

and btw, 'hostname -s' fails unless you're root, on my system.
________________________________________________________________________
Andrew Hay                                  the genius nature
internet rambler                            is to see what all have seen
adh at an.bradford.ma.us                       and think what none thought



More information about the rescue mailing list