Thread View: comp.unix.shell
3 messages
3 total messages
Started by Jonathan Bayer
Fri, 14 Sep 1990 03:00
command line prompt (need current directory)
Author: Jonathan Bayer
Date: Fri, 14 Sep 1990 03:00
Date: Fri, 14 Sep 1990 03:00
38 lines
1318 bytes
1318 bytes
I know that this subject comes up about once a year or so. Now it is my
turn :-)
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:
c() # you might not be able to name this function `cd'
{
cd $1
PS1="`pwd`> "
}
This was placed into /etc/profile, and works well, until a new shell is
spawned. The new shell does not inherit the shell function. My
questions are:
1. How can I make the new shell inherit shell functions?
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)?
I will summarize to the net after stripping out all extraneous lines and
comments.
Thank you.
JB
--
Jonathan Bayer Intelligent Software Products, Inc.
(201) 245-5922 500 Oakwood Ave.
jbayer@ispi.COM Roselle Park, NJ 07204
Re: command line prompt (need current directory)
Author: BURNS,JIM
Date: Fri, 14 Sep 1990 11:29
Date: Fri, 14 Sep 1990 11:29
47 lines
1984 bytes
1984 bytes
in article <1683@ispi.COM>, jbayer@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@prism.gatech.edu
Re: command line prompt (need current directory)
Author: Chet Ramey
Date: Fri, 14 Sep 1990 13:55
Date: Fri, 14 Sep 1990 13:55
31 lines
1750 bytes
1750 bytes
In article <13669@hydra.gatech.EDU> gt0178a@prism.gatech.EDU (BURNS,JIM) writes: >Ksh allows you to export functions with (for me): > >typeset -fx cp ll man This will not export the functions to separate invocations of ksh. Only shells `spawned' by ksh to execute scripts will inherit these function definitions. There is no way to export functions to separate invocations of the shell; you must do it via the $ENV file. >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). There aren't any. >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: The Korn Shell and Bash will do alias substitution first. It's really the last stage of token recognition rather than part of command execution. For bash, the order of lookup is function, builtin, file system (Posix is the same way). For ksh, it's builtin, function, file system. Chet -- Chet Ramey ``Levi Stubbs' tears run down Network Services Group his face...'' Case Western Reserve University chet@ins.CWRU.Edu
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads