KSH-How do I make a variable run a function upon invocation?

J.B. Nicholson jbn35564 at uxa.cso.uiuc.edu
Wed Apr 10 11:24:29 AEST 1991


In KSH I want to make ${PS1} take on a value where it executes a function called
PS1, but not take on the output from the function itself.  Here's what I mean:

function PS1 {
shrunkhome=${PWD%${HOME}/}
case ${shrunkhome} in
	${HOME})	shrunkhome=\~/ ;;
esac
HOSTNAME=$(hostname)
print -n '<'${USER}'@'${HOSTNAME%%.*}':'${shrunkhome}'> ' ;;
}

...then I want to define...

export PS1=$(PS1)

but that only works the first time I use ${PS1}.  I'd like to define it as:

export PS1=[just run the function called](PS1)

but I don't know how to make that definition.  I've tried having an alias
for cd:

alias -x cd='_cd'

and a function (defined before that alias was set) called _cd that basically
assigns ${PS1} to the right value somewhat similar to above, except passing
arguments to the REAL cd program (to maintain compatibility) but every time
I access cd, won't this function _cd run?  Also, all my error messages come
from _cd and not cd.  That's rather annoying to me.  Anyways, I figure keeping
this whole thing inside ${PS1} would not void any warranties, cause any
mayhem or incompatibilities or whatever. :-)

So, basically what I'm asking is:  How do I do this?

Thanks in advance,
Jeff
--
+----------------------------------------------------------------------------+
| "If you hear an onion ring - answer it."                    J.B. Nicholson |
+----------------------------------------------------------------------------+
| jeffo at uiuc.edu (Internet)              These opinions are mine, that's all.|
+----------------------------------------------------------------------------+



More information about the Comp.unix.questions mailing list