Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!wuarchive!psuvax1!rutgers!cmcl2!rnd!cliu From: cliu@rnd.GBA.NYU.EDU (Crocker H. Liu) Newsgroups: comp.sys.3b1 Subject: Re: Ksh Summary: my .profile and .env files Keywords: ksh Message-ID: <9329@rnd.GBA.NYU.EDU> Date: 6 Feb 91 05:28:02 GMT References: <52@morwyn.UUCP> <11688@helios.TAMU.EDU> Reply-To: cliu@rnd.UUCP (Crocker H. Liu) Distribution: comp Organization: NYU Stern School of Business Lines: 81 In article <11688@helios.TAMU.EDU> Brent Burton writes: > >In ksh, I remember the main prompt being PS1. So, >it would be something like: > SET PS1="MY-PROMPT\!" > Actually, this won't work. To get a ! in your prompt you just need to put use two exclamation marks, !!. I'll use my prompt as an example. Sometimes I'm nested several deep in invocations of ksh. Each time I invoke a new ksh, I keep track of how deep I am by adding another exclamation point to my prompt. For example, if I have just logged in my prompt looks like: /u/crocker> If I now run a new ksh, the prompt changes to: /u/crocker!> When I exit from the ksh, the exclamation point is removed. My ~/.profile looks like: # shell used by emacs ESHELL=/bin/ksh; export ESHELL # ksh startup commands file ENV=$HOME/.env; export ENV # I use a modified window manager, so that I can create multiple # windows and log in to each. Each window gets its own history file. TTY="`tty`" HISTFILE="$HOME/.ksh`basename $TTY`"; export HISTFILE trap "rm $HISTFILE" 0 # remove the history file on logout # don't allow ^D for logout case $SHELL in *ksh) set -o ignoreeof;; # don't allow ^D for logout esac Since the prompt depends on the level of nesting of ksh, it is set in the ksh commands file, ~/.env: set +o verbose case $- in *i*) # interactive set -o emacs set -o monitor alias h='fc -l | tail -23 | more -c alias c='clear' alias w='whence' alias v='dvi3b1 /tmp/TeXzap.dvi' # Add two exclamation marks each time ksh is invoked. # In the prompt this shows up as one added exclamation point level="${level}!!"; export level # Remove one pair of exclamation points, so that the lowest level # prompt doesn't show any exclamation points. Since the ksh invoked # in emacs by the M-x shell command is the second level of nesting, # one needs to remove two pairs of exclamation points to have the # lowest level prompt not show any exclamation points. if [ "$EMACS" ] then PS1='$PWD'${level#!!!!}'> ' else PS1='$PWD'${level#!!}'> ' fi ;; *) set -o errexit ;; esac [ "$EMACS" ] && set -o verbose The prompt uses '$PWD' instead of "$PWD" because the latter would be immediately evaluated when ~/.env is executed, instead of being evaluated each time the prompt is displayed. Unlike the current directory, the level of nesting doesn't change, so that part of the prompt can be evaluated once and for all when the ~/.env file is run through. Hope this helps! ......................................................................... Crocker Liu INTERNET: cliu@rnd.gba.nyu.edu USENET: ...!{uunet,rocky,harvard}!cmcl2!rnd!cliu