Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!sdd.hp.com!spool.mu.edu!news.nd.edu!mentor.cc.purdue.edu!sage.cc.purdue.edu!asg From: asg@sage.cc.purdue.edu (Bruce Varney) 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: <10052@mentor.cc.purdue.edu> Date: 10 Apr 91 22:15:05 GMT Article-I.D.: mentor.10052 References: <1991Apr10.035042.3008@ux1.cso.uiuc.edu> <10009@mentor.cc.purdue.edu> <1991Apr10.190259.9524@ux1.cso.uiuc.edu> Sender: news@mentor.cc.purdue.edu Reply-To: asg@sage.cc.purdue.edu (Bruce Varney) Organization: Purdue University Lines: 80 In article <1991Apr10.190259.9524@ux1.cso.uiuc.edu> jeffo@uiuc.edu writes: }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. Wrong Wrong Wrong There is a man page for bash. Tell you what - ftp to slc2.ins.cwru.edu and get the file /pub/(This is either gnu or bash)/bash-1.07.cwru.tar.Z uncompress and untar it It will contain the source for bash 1.07 as well as the man page which is in documentation/bash.1 Just do a: cd documentation mroff -man bash.1 > bash.man more bash.man and you will get to read the bash man page. Most of bashes functionality is just like KSH. The only differences are the additions ( and the loss of select and let, but $[] replaces let). } }>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) try PS1=\$(simpleattempt) } }But that makes ${PS1}: }this is coming from simpleattempt() } }to be substituted into the contents of ${PS1}, I just want ${PS1} to run }that function whenever ${PS1} is called. As I said, you can use the PROMPT_COMMAND variable in bash - just look it up in the man page ;-) } }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. So try bash!!! --------- ### ## Courtesy of Bruce Varney ### # aka -> The Grand Master # asg@sage.cc.purdue.edu ### ##### # PUCC ### # ;-) # # ;'> # ##