command line prompt (need current directory)

BURNS,JIM gt0178a at prism.gatech.EDU
Fri Sep 14 21:29:42 AEST 1990


in article <1683 at ispi.COM>, jbayer at ispi.COM (Jonathan Bayer) says:
> I have a customer who wants/needs the prompt to show the current
> directory (similar to MS-DOS :-(  ).  I reached back into my archives
> and pulled out the following script:

In .kshrc, I do:

PS1="{${HOSTNAME}"':${PWD}}\
[!] '

In .cshrc, I do:

alias cd 'cd \!*;set prompt="`hostname``pwd`> [\\!] % "'
cd `pwd`

Putting them in the rc's executes them for each subshell. (The !'s are the
current history #'s.)

> spawned.  The new shell does not inherit the shell function.  My
> questions are:
> 
> 	1.	How can I make the new shell inherit shell functions?

Ksh allows you to export functions with (for me):

typeset -fx cp ll man

I'm not aware of any way to do it in sh, and haven't run across any csh's
that support functions, per se (not aliases).

> 	2.	Is it possible to have a shell function have the same
> 		name as a real function (ie:  name this function "cd",
> 		and have it use the normal "cd" to change the
> 		directory)?

Most shells will search for a builtin before executing an alias or
function. For a function that replaces the behavior of an external,
specify the pathname for the 'inside' invocation of the command, as in:

ll () { /bin/ls -alF $* | more ; }

This can be particularly important in shells that allow recursion!
-- 
BURNS,JIM
Georgia Institute of Technology, Box 30178, Atlanta Georgia, 30332
uucp:	  ...!{decvax,hplabs,ncar,purdue,rutgers}!gatech!prism!gt0178a
Internet: gt0178a at prism.gatech.edu



More information about the Comp.unix.shell mailing list