Q: How to have cd echo $cwd in all shells (Please)

Q: How to have cd echo $cwd in all shells (Please)

Post by uh33.. » Thu, 04 Aug 1994 17:44:28



Hello,
this is a bit of a beginners question, but I hope that's okay. What I
want is something very simple: Have cd echo the current directory each
time it is called. I know how to make a proper alias for that purpose
in csh and tcsh. But I have no clue how to do that in bourne shell
variants and others (sh, bash, ksh, zsh etc). So, if you know how,
please drop me a one-liner.

Thanks !
Henrik

 
 
 

Q: How to have cd echo $cwd in all shells (Please)

Post by Richard Colem » Fri, 05 Aug 1994 03:40:31


Quote:>   this is a bit of a beginners question, but I hope that's okay. What I
>   want is something very simple: Have cd echo the current directory each
>   time it is called. I know how to make a proper alias for that purpose
>   in csh and tcsh. But I have no clue how to do that in bourne shell
>   variants and others (sh, bash, ksh, zsh etc). So, if you know how,
>   please drop me a one-liner.

In zsh, it is very easy.  The shell function "chpwd" if defined,
is executed whenever the current working directory is changed.
So just define the function like:

% chpwd() { echo $PWD }

Richard Coleman


 
 
 

Q: How to have cd echo $cwd in all shells (Please)

Post by A.Park » Fri, 05 Aug 1994 17:48:48



>Hello,
>this is a bit of a beginners question, but I hope that's okay. What I
>want is something very simple: Have cd echo the current directory each
>time it is called. I know how to make a proper alias for that purpose
>in csh and tcsh. But I have no clue how to do that in bourne shell
>variants and others (sh, bash, ksh, zsh etc). So, if you know how,
>please drop me a one-liner.
>Thanks !
>Henrik

In  bash  the  current directory can be included  by  adding  the
characters \w to your PS1 variable.

eg. bash$ PS1="\w> ";export PS1
    ~> cd /usr
    /usr>

Hope this helps.

Andy.