KSHPR: prompt generator for .kshrc

Thad P Floryan thad at cup.portal.com
Fri Jun 23 22:28:53 AEST 1989


The following is a l'il qwik'n'dirty you may find useful.  If you know of some
other method to determine whether one is running su'd or not, please share it.
This posting is to unix-pc.sources and comp.sys.att since it's of potential use
to any UNIX user of ksh.

#	This is a shell archive.
#	Remove everything above and including the cut line.
#	Then run the rest of the file through sh.
#----cut here-----cut here-----cut here-----cut here----#
#!/bin/sh
# shar:    Shell Archiver
#	Run the following text with /bin/sh to create:
#	README
#	Makefile
#	kshpr.c
# This archive created: Fri Jun 23 05:24:03 1989
echo shar: extracting README
sed 's/^X//' << \SHAR_EOF > README
X"Kshpr" is the proverbial "one-line" program you may find interesting and
Xuseful.  It is the result of my requirement for a different prompt while
Xoperating ksh su'd.
X
XAfter several kludge attempts, including attempts to process the output of
X`id`, I couldn't find an obvious way to detect the su'd condition directly
Xin the shell, so "kshpr" was born.
X
XKshpr is intended for use in a .kshrc script per:
X
X	PS1=`/usr/local/bin/kshpr`
X
Xkshpr's normal output is:  "ksh $PPID/$$> "
Xkshpr's output if su'd is: "ksh-su $PPID/$$# "
X
X$PPID is the parent process' ID; if it's a 1, then I know that typing a ^D
Xwill log me out.  $$ is the process ID of "this" process (e.g. this instance
Xof the ksh).  The typical display of the prompt is "ksh 1/2345> " and is
X"ksh-su 2345/6789# " when running as superuser.
X
XAfter many futile attempts using other approaches, my notes don't indicate
Xwhether one MUST specify /bin/ksh as the login shell for root or not (in the
X/etc/passwd file), but it's that way on my systems now and all works fine.
X
XThad Floryan [ thad at cup.portal.com (OR) ..!sun!portal!cup.portal.com!thad ]
SHAR_EOF
if test 1104 -ne "`wc -c README`"
then
echo shar: error transmitting README '(should have been 1104 characters)'
fi
echo shar: extracting Makefile
sed 's/^X//' << \SHAR_EOF > Makefile
X# Makefile for kshpr
X#
X# Uncomment the line for your favorite compiler
X#
X#CC=	cc
XCC=	gcc
X
XCFLAGS=	-O
X
Xkshpr:		kshpr.o
X		ld /lib/crt0s.o /lib/shlib.ifile kshpr.o -o kshpr -s
X		rm -f kshpr.o
X
Xkshpr.o:	kshpr.c
X		$(CC) $(CFLAGS) -c kshpr.c
SHAR_EOF
if test 236 -ne "`wc -c Makefile`"
then
echo shar: error transmitting Makefile '(should have been 236 characters)'
fi
echo shar: extracting kshpr.c
sed 's/^X//' << \SHAR_EOF > kshpr.c
X/*	kshpr
X *
X *	This program displays my idea of a ksh prompt which is different for a
X *	normal user than it is for a su'd user.
X *
X *	Kshpr is intended for use in a .kshrc script per:
X *
X *		PS1=`/usr/local/bin/kshpr`
X *
X *	The normal output is:  "ksh $PPID/$$> ", and
X *	the output if su'd is: "ksh-su $PPID/$$# "
X *
X *	Thad Floryan, 3-June-1989
X */
X
X#include <stdio.h>
X
Xextern int getuid();
X
Xmain()
X{
X	if (getuid() == 0) fprintf(stdout, "ksh-su $PPID/$$# ");
X	else               fprintf(stdout, "ksh $PPID/$$> ");
X}
SHAR_EOF
if test 519 -ne "`wc -c kshpr.c`"
then
echo shar: error transmitting kshpr.c '(should have been 519 characters)'
fi
#	End of shell archive
exit 0



More information about the Unix-pc.sources mailing list