Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!zaphod.mps.ohio-state.edu!caen!news.cs.indiana.edu!ux1.cso.uiuc.edu!uxa.cso.uiuc.edu!jbn35564 From: jbn35564@uxa.cso.uiuc.edu (J.B. Nicholson) Newsgroups: comp.unix.shell Subject: Re: KSH-How do I make a variable run a function upon invocation? Keywords: KSH function variable assignment substitution Message-ID: <1991Apr10.190259.9524@ux1.cso.uiuc.edu> Date: 10 Apr 91 19:02:59 GMT References: <1991Apr10.035042.3008@ux1.cso.uiuc.edu> <10009@mentor.cc.purdue.edu> Sender: usenet@ux1.cso.uiuc.edu (News) Reply-To: jeffo@uiuc.edu Organization: University of Illinois at Urbana Lines: 63 In <10009@mentor.cc.purdue.edu> asg@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@uiuc.edu (Internet) These opinions are mine, that's all.| +----------------------------------------------------------------------------+