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

Bruce Varney asg at sage.cc.purdue.edu
Thu Apr 11 00:39:28 AEST 1991


In article <1991Apr10.035042.3008 at ux1.cso.uiuc.edu> jeffo at uiuc.edu writes:
}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:
}
}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
}Thanks in advance,
}  Jeff
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.
Thus you could do something line
PS1="\$WD ->"
PROMPT_COMMAND = "WD = `working_dir`"
working_dir() {
whatever you use to prune the dir name
}
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
alias -x x=cd
alias -x cd='cd_help'
cd_help() {
whatever you use to prune the dir name
x $1
}

that will work just fine (or should). 
		Hope this helps
			As Always
			   The Grand Master

---------
                                   ###             ##
Courtesy of Bruce Varney           ###               #
aka -> The Grand Master                               #
asg at sage.cc.purdue.edu             ###    #####       #
PUCC                               ###                #
;-)                                 #                #
;'>                                #               ##



More information about the Comp.unix.shell mailing list