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

J.B. Nicholson jbn35564 at uxa.cso.uiuc.edu
Thu Apr 11 05:02:59 AEST 1991


In <10009 at mentor.cc.purdue.edu> asg at sage.cc.purdue.edu (Bruce Varney) writes:

>Here is the scoop - there are two possibilities
>The first and easiest (IMHO) is to switch shells to bash. bash has a variable
>PROMPT_COMMAND which is a command to run before the prompt is printed.

This sounds very nice, but BASH has no documentation (that I know of) beyond
the helpscreen, which isn't like having at least a long man page at your
fingertips.  When more docs become available for BASH, I'll take a serious look
at it, 'till then, I'll have to stick with KSH.

>Course if you are stuck on ksh, this will also work. Note that it will not work
>with csh as ksh and csh handle aliases different
[...description deleted...]
>that will work just fine (or should). 
>		Hope this helps
>			As Always
>			   The Grand Master

Well, I've tried using that idea:

function simpleattempt {
print -n 'this is coming from simpleattempt()'
}

and then:

PS1='simpleattempt'

will make your prompt:
simpleattempt

so, I tried:

PS1=$(simpleattempt)

But that makes ${PS1}:
this is coming from simpleattempt()

and I need ${PS1} to retain the value of '$(simpleattempt)' or whatever the
command is to make a function run.  I don't want the output of simpleattempt()
to be substituted into the contents of ${PS1}, I just want ${PS1} to run
that function whenever ${PS1} is called.

I tried a method of doing this where cd is aliased to a function that does all
the calculations necessary for the prompt string and performs the regular cd
command (called _cd), but I got error messages from _cd and not cd.  Also, if
anything was run to reference the KSH's cd command, it would go through all my
prompt string stuff slowing it down a lot.

Therefore, I'm trying to keep all this prompt string modification inside of
${PS1}.

If I just had a way for ${PS1} to run a function without changing the value of
${PS1}, I'd be set.

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.shell mailing list