bug in cd

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

bug in cd

Kae Verens
I'm not even sure if cd is part of Bash?

anyway - if you type any of the following:
cd / ; pwd
cd /// ; pwd
cd //// ; pwd

the CLI always reports
/

but, if you do this:
cd // ; pwd

then the CLI reports
//

--
Kae Verens
http://kvsites.ie/
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: bug in cd

Chet Ramey
On 7/14/17 7:14 AM, Kae Verens wrote:
> I'm not even sure if cd is part of Bash?

It is. It's a regular shell builtin.

> anyway - if you type any of the following:
> cd / ; pwd
> cd /// ; pwd
> cd //// ; pwd
>
> the CLI always reports
> /
>
> but, if you do this:
> cd // ; pwd
>
> then the CLI reports
> //

Posix requires this behavior:

http://pubs.opengroup.org/onlinepubs/9699919799/utilities/cd.html#tag_20_14

step 8c.

Two leading slashes must be preserved, because // has implementation-
defined semantics. Any other number may be collapsed to one slash.

--
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    [hidden email]    http://cnswww.cns.cwru.edu/~chet/

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: bug in cd

Bob Proulx
In reply to this post by Kae Verens
Kae Verens wrote:
> but, if you do this:
> cd // ; pwd
>
> then the CLI reports
> //

Using two "//" at the start of a path name is special because in some
systems it means the path component that follows is a hostname.
Therefore it must be preserved verbatim.

Bob

Loading...