'cd' does 'pwd' with relative path but not with absolute path - documented?

Chris Green cl at isbd.net
Fri Jul 3 09:14:27 UTC 2020


On Fri, Jul 03, 2020 at 10:56:40AM +0200, Volker Wysk wrote:
> Am Freitag, den 03.07.2020, 09:28 +0100 schrieb Chris Green:
> > I have only recently noticed that when running bash in a terminal
> > 'cd'
> > acts differently for relative and absolute paths.
> > 
> > If you do a cd to an absolute path it outputs nothing but if you cd
> > to
> > a relative path it outputs (i.e. does a pwd) the path after changing
> > directory.
> > 
> > For example:-
> > 
> >     chris$ cd
> >     chris$ cd /tmp
> >     chris$ cd scans
> >     /tmp/scans
> >     chris$ 
> 
> I can't reproduce this. It doesn't output the new path on my machine:
> 
> desktop ~ $ mkdir /tmp/scans
> desktop ~ $ cd /tmp
> desktop /tmp $ cd scans
> desktop /tmp/scans $ 
> 
Yes, it's odd.  I must say I had assumed that after cd the destination
path was *always* reported but then I noticed the cases where it
wasn't reported.

I'm running xubuntu 19.10 by the way, almost certainly works the same
as ubuntu 19.10.  I have just tried it in an 18.04.4 LTS system I
have, it does the same there:-

    chris at backup$ builtin cd /tmp
    chris at backup$ builtin cd scans
    /tmp/scans
    chris at backup$ more /etc/issue
    Ubuntu 18.04.4 LTS \n \l

(I had to use 'builtin cd' to make sure I was running the 'real' bash
builtin cd command)

I've just had a thought, presumably this reporting of the destination
directory *only* happens when running interactively at a terminal,
otherwise a cd in a script would produce (almost certainly unwanted)
output.

But *no*! I just wrote a script:-

    #!/bin/bash

    builtin cd /tmp
    builtin cd scans

... and running it produces some output:-

    chris$ cd /tmp
    chris$ ./cdscript
    /tmp/scans
    chris$ 

I get the feeling that there must be some sort of configuration
somewhere that turns this on and I've turned it on somehow.  I've
looked in my .bashrc and in /tmp/bash.bashrc and can't see anything
obvious.  However I will try running bash without any config files and
see if that reveals anything.

-- 
Chris Green




More information about the ubuntu-users mailing list