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

Bruce Varney asg at sage.cc.purdue.edu
Thu Apr 11 08:15:05 AEST 1991


In article <1991Apr10.190259.9524 at ux1.cso.uiuc.edu> jeffo at uiuc.edu writes:
}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.
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 at sage.cc.purdue.edu             ###    #####       #
PUCC                               ###                #
;-)                                 #                #
;'>                                #               ##



More information about the Comp.unix.shell mailing list