Strange behaviour of the "cd" command

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
17 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Strange behaviour of the "cd" command

Dr Rainer Woitok
Greetings,

On a rather fresh installation of Kubuntu 16.04 I ran into the following
problem:

General information:

$ uname -a
Linux tux 4.4.0-81-generic #104-Ubuntu SMP Wed Jun 14 08:17:06 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
$ echo $SHELL
/usr/bin/ksh
$ unset CDPATH
$ ls -la / | head -4
total 116
drwxr-xr-x  24 root root  4096 2017-06-26 19:05 .
drwxr-xr-x  24 root root  4096 2017-06-26 19:05 ..
drwx------   2 root root  4096 2016-05-25 11:19 .cache
$ cd /.cache
/usr/bin/ksh: hist[7]: cd: /.cache: [Permission denied]

The above message is exactly what one would expect, and thus ok.

$ cd
$ pwd
/home/rainer
$ ls -la ../../ | head -4
total 116
drwxr-xr-x  24 root root  4096 2017-06-26 19:05 .
drwxr-xr-x  24 root root  4096 2017-06-26 19:05 ..
drwx------   2 root root  4096 2016-05-25 11:19 .cache
$ cd ../../.cache
/usr/bin/ksh: hist[11]: cd: /cache: [No such file or directory]
$ pwd
/home/rainer

However, the error message above  is definitely not what I had expected!
In the error message mind in particular the missing dot in "/cache".

What's happening here?

Sincerely,
  Rainer

--
ubuntu-users mailing list
[hidden email]
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Strange behaviour of the "cd" command

Joel Rees
One question occurs to me ...

On Mon, Jul 10, 2017 at 9:58 PM, Dr Rainer Woitok
<[hidden email]> wrote:

> Greetings,
>
> On a rather fresh installation of Kubuntu 16.04 I ran into the following
> problem:
>
> General information:
>
> $ uname -a
> Linux tux 4.4.0-81-generic #104-Ubuntu SMP Wed Jun 14 08:17:06 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
> $ echo $SHELL
> /usr/bin/ksh
> $ unset CDPATH
> $ ls -la / | head -4
> total 116
> drwxr-xr-x  24 root root  4096 2017-06-26 19:05 .
> drwxr-xr-x  24 root root  4096 2017-06-26 19:05 ..
> drwx------   2 root root  4096 2016-05-25 11:19 .cache
> $ cd /.cache
> /usr/bin/ksh: hist[7]: cd: /.cache: [Permission denied]

What is that directory doing there?

Now, I have a /root/.cache even though I rarely enable root for even
local log in, and never log into a gui environment as root, and never
use lynx or such as root.

Having a /.cache might indicate that something succeeded half-way
at su-ing to root without enough permission to read root's login directory,
or something like that.

> The above message is exactly what one would expect, and thus ok.
>
> $ cd
> $ pwd
> /home/rainer
> $ ls -la ../../ | head -4
> total 116
> drwxr-xr-x  24 root root  4096 2017-06-26 19:05 .
> drwxr-xr-x  24 root root  4096 2017-06-26 19:05 ..
> drwx------   2 root root  4096 2016-05-25 11:19 .cache
> $ cd ../../.cache
> /usr/bin/ksh: hist[11]: cd: /cache: [No such file or directory]

I made a /.cache directory, just for grins, but I don't reproduce this. My
shell is bash. I didn't think to see what would happen if there were
a /.cache and a /cache which somehow were hard links to the same
inode. At least we know that your /.cache is not a symbolic link. What
does ls -i tell you?

Check whether you have an executable called "cd" somewhere in
your PATH. (You shouldn't, of course.)

If you don't find an executable called cd lying around in your path,
check that your shell has not been modified.

> $ pwd
> /home/rainer
>
> However, the error message above  is definitely not what I had expected!
> In the error message mind in particular the missing dot in "/cache".
>
> What's happening here?
>
> Sincerely,
>   Rainer
>
> --
> ubuntu-users mailing list
> [hidden email]
> Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users



--
Joel Rees

One of these days I'll get someone to pay me
to design a language that combines the best of Forth and C.
Then I'll be able to leap wide instruction sets with a single #ifdef,
run faster than a speeding infinite loop with a #define,
and stop all integer size bugs with my bare cast.
http://defining-computers.blogspot.com/2017/06/reinventing-computers.html

More of my delusions:
http://reiisi.blogspot.com/2017/05/do-not-pay-modern-danegeld-ransomware.html
http://reiisi.blogspot.jp/p/novels-i-am-writing.html

--
ubuntu-users mailing list
[hidden email]
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Strange behaviour of the "cd" command

blind Pete
In reply to this post by Dr Rainer Woitok
Dr Rainer Woitok wrote:

> Greetings,
>
> On a rather fresh installation of Kubuntu 16.04 I ran into the following
> problem:
>
> General information:
>
> $ uname -a
> Linux tux 4.4.0-81-generic #104-Ubuntu SMP Wed Jun 14 08:17:06 UTC 2017
> x86_64 x86_64 x86_64 GNU/Linux $ echo $SHELL
> /usr/bin/ksh
> $ unset CDPATH
> $ ls -la / | head -4
> total 116
> drwxr-xr-x  24 root root  4096 2017-06-26 19:05 .
> drwxr-xr-x  24 root root  4096 2017-06-26 19:05 ..
> drwx------   2 root root  4096 2016-05-25 11:19 .cache
> $ cd /.cache
> /usr/bin/ksh: hist[7]: cd: /.cache: [Permission denied]
>
> The above message is exactly what one would expect, and thus ok.
>
> $ cd
> $ pwd
> /home/rainer
> $ ls -la ../../ | head -4
> total 116
> drwxr-xr-x  24 root root  4096 2017-06-26 19:05 .
> drwxr-xr-x  24 root root  4096 2017-06-26 19:05 ..
> drwx------   2 root root  4096 2016-05-25 11:19 .cache

   ^^^^^^^^^

Root has read, write and execute permission for that
directory, nobody else may cd into it.  


> $ cd ../../.cache
> /usr/bin/ksh: hist[11]: cd: /cache: [No such file or directory]
> $ pwd
> /home/rainer

No such directory is available to ordinary users
like "rainer".  

If you are good friends with the system administrator try;

sudo ls -al /.cache
or
sudo chown rainer:rainer /.cache
or
sudo chmod 755 /.cache

> However, the error message above  is definitely not what I had expected!
> In the error message mind in particular the missing dot in "/cache".
>
> What's happening here?

The error message could be better.  If it worries you take it up with
the shell maintainers.  

> Sincerely,
>   Rainer

--
blind Pete
Sig goes here...  


--
ubuntu-users mailing list
[hidden email]
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Strange behaviour of the "cd" command

Ken D'Ambrosio
In reply to this post by Dr Rainer Woitok
The problem is with ksh -- specifically (I think) ksh's implementation
of 'cd'.  I fired up ksh, and also created a /.cache directory (and a
/.foo), and here are some results:

$ cd /.foo  # success
$ cd /.cache # success
$ cd /tmp # success
$ cd ../.foo # failure
ksh: cd: /foo: [No such file or directory]
$ cd ../.cache # failure
ksh: cd: /cache: [No such file or directory]
$ cd ../tmp # success

The thing I find most telling is the error messages, themselves: "/foo:
No such file or directory".
My *guess* as to what is happening is that it is interpreting the
leading "." as *the directory* ".", meaning "this directory", meaning,
in this case, "root", thus the "directory" it's thinking about is
"/foo", *not* "/.foo".

Congrats.  I could be wrong, but I do believe you've found a bug.

-Ken


On 2017-07-10 08:58, Dr Rainer Woitok wrote:

> Greetings,
>
> On a rather fresh installation of Kubuntu 16.04 I ran into the
> following
> problem:
>
> General information:
>
> $ uname -a
> Linux tux 4.4.0-81-generic #104-Ubuntu SMP Wed Jun 14 08:17:06 UTC
> 2017 x86_64 x86_64 x86_64 GNU/Linux
> $ echo $SHELL
> /usr/bin/ksh
> $ unset CDPATH
> $ ls -la / | head -4
> total 116
> drwxr-xr-x  24 root root  4096 2017-06-26 19:05 .
> drwxr-xr-x  24 root root  4096 2017-06-26 19:05 ..
> drwx------   2 root root  4096 2016-05-25 11:19 .cache
> $ cd /.cache
> /usr/bin/ksh: hist[7]: cd: /.cache: [Permission denied]
>
> The above message is exactly what one would expect, and thus ok.
>
> $ cd
> $ pwd
> /home/rainer
> $ ls -la ../../ | head -4
> total 116
> drwxr-xr-x  24 root root  4096 2017-06-26 19:05 .
> drwxr-xr-x  24 root root  4096 2017-06-26 19:05 ..
> drwx------   2 root root  4096 2016-05-25 11:19 .cache
> $ cd ../../.cache
> /usr/bin/ksh: hist[11]: cd: /cache: [No such file or directory]
> $ pwd
> /home/rainer
>
> However, the error message above  is definitely not what I had
> expected!
> In the error message mind in particular the missing dot in "/cache".
>
> What's happening here?
>
> Sincerely,
>   Rainer

--
ubuntu-users mailing list
[hidden email]
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
Xen
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Strange behaviour of the "cd" command

Xen
Ken D'Ambrosio schreef op 11-07-2017 17:55:

> The problem is with ksh -- specifically (I think) ksh's implementation
> of 'cd'.  I fired up ksh, and also created a /.cache directory (and a
> /.foo), and here are some results:
>
> $ cd /.foo  # success
> $ cd /.cache # success
> $ cd /tmp # success
> $ cd ../.foo # failure
> ksh: cd: /foo: [No such file or directory]
> $ cd ../.cache # failure
> ksh: cd: /cache: [No such file or directory]
> $ cd ../tmp # success
>
> The thing I find most telling is the error messages, themselves:
> "/foo: No such file or directory".
> My *guess* as to what is happening is that it is interpreting the
> leading "." as *the directory* ".", meaning "this directory", meaning,
> in this case, "root", thus the "directory" it's thinking about is
> "/foo", *not* "/.foo".
>
> Congrats.  I could be wrong, but I do believe you've found a bug.

Or maybe it has all kinds of speed-up features that you might have
triggered.

--
ubuntu-users mailing list
[hidden email]
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Strange behaviour of the "cd" command

Ken D'Ambrosio
On 2017-07-11 12:17, Xen wrote:

> Or maybe it has all kinds of speed-up features that you might have
> triggered.

Not even sure what you mean by "speed-up" feature, especially when it
violates pretty dramatically the "least astonishment" principle.

1) How *would* you cd to a directory preceded by a . using relative
nomenclature if not the one already described?
2) Why would you be able to cd into it using absolute nomenclature?
3) It completely violates non-built-in nomenclature, such as that used
by "ls" or even "rmdir" and "mkdir"
4) Lastly, it clearly violates safe-use nomenclature:

$ pwd
/tmp
$ mkdir -p one/two
$ mkdir .three
$ cd one/two
$ cd ../../.three
ksh: cd: /tmp/three: [No such file or directory]
$ mkdir ../../three
$ cd ../../.three
$ pwd
/tmp/three

Et voila!  Suddenly, you're not in the directory you explicitly
specified on your CLI.  That's a Bad Thing(tm).  I have a really hard
time believing someone would modify "."'s funcionality *while part of a
pathname*.  That way lies madness and deleted files.

$.02,

-Ken

--
ubuntu-users mailing list
[hidden email]
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
Xen
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Strange behaviour of the "cd" command

Xen
Ken D'Ambrosio schreef op 11-07-2017 19:39:
> On 2017-07-11 12:17, Xen wrote:
>
>> Or maybe it has all kinds of speed-up features that you might have
>> triggered.
>
> Not even sure what you mean by "speed-up" feature, especially when it
> violates pretty dramatically the "least astonishment" principle.

I am no expert. I am just saying the Korn Shell and the Z Shell have
speed up features that make for easier navigation, but I don't remember
them.

--
ubuntu-users mailing list
[hidden email]
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Strange behaviour of the "cd" command

Dr Rainer Woitok
In reply to this post by Joel Rees
Joel,

On Tuesday, 2017-07-11 10:51:53 +0900, you wrote:

> ...
> > $ echo $SHELL
> > /usr/bin/ksh
> > $ unset CDPATH
> > $ ls -la / | head -4
> > total 116
> > drwxr-xr-x  24 root root  4096 2017-06-26 19:05 .
> > drwxr-xr-x  24 root root  4096 2017-06-26 19:05 ..
> > drwx------   2 root root  4096 2016-05-25 11:19 .cache
> > $ cd /.cache
> > /usr/bin/ksh: hist[7]: cd: /.cache: [Permission denied]
> ...
> Having a /.cache might indicate that something succeeded half-way
> at su-ing to root without enough permission to read root's login directory,
> or something like that.

You might well be right.  But for the case at hand it doesn't matter.  I
just used this directory as a guinea pig to demonstrate the problem.

> ...
> I made a /.cache directory, just for grins, but I don't reproduce this. My
> shell is bash.

But as one can see from the output of "echo $SHELL" above, I used a Korn
Shell.  And since the "cd" command is a shell built-in, I'm not surpris-
ed you can't reproduce the problem using a Bash Shell.

> ...
> Check whether you have an executable called "cd" somewhere in
> your PATH. (You shouldn't, of course.)

I haven't, of course.  But you're right, I should have added the command
"whence cd" to the problem description.

Sincerely,
  Rainer

--
ubuntu-users mailing list
[hidden email]
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Strange behaviour of the "cd" command

Dr Rainer Woitok
In reply to this post by Ken D'Ambrosio
Ken,

On Tuesday, 2017-07-11 13:39:21 -0400, you wrote:

> ...
> $ mkdir ../../three
> $ cd ../../.three
> $ pwd
> /tmp/three

Congrats back to you :-)

I hadn't yet found this one.   But this clearly indicates  that the Korn
Shell's built-in "cd" command is really dropping the dot from the relat-
ive path  in this case.   By pure chance  I meanwhile happened to find a
workaround.  Slightly changing your last two commands above yields

   $ cd ../..//.three
   $ pwd
   /tmp/.three

Thus duplicating the slash preceeding the dot  prevents the dot from be-
ing dropped.  Just to add some more information I have forgotten to pro-
vide in my original post:

   $ echo $KSH_VERSION
   Version AJM 93u+ 2012-08-01

And as an aside, I also have a Korn Shell running on a Windows box under
Cygwin which does NOT  exhibit the  strange behaviour  described in this
thread.   This one has a value of "@(#)MIRBSD KSH R54 2016/11/11" stored
in shell variable "KSH_VERSION", making it considerably more recent.

What now?  Are there any Korn Shell developers or maintainers listening?

Sincerely,
  Rainer

--
ubuntu-users mailing list
[hidden email]
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Strange behaviour of the "cd" command

Dr Rainer Woitok
In reply to this post by Xen
Xen,

On Tuesday, 2017-07-11 19:44:29 +0200, you wrote:

> ...
> I am no expert. I am just saying the Korn Shell and the Z Shell have
> speed up features that make for easier navigation, but I don't remember
> them.

The only Korn Shell specific speed-up features for easier navigation I'm
aware of is environment variable "CDPATH",  which I had explicitly unset
at the beginning of my command sequence describing the problem.

Sincerely,
  Rainer

--
ubuntu-users mailing list
[hidden email]
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Strange behaviour of the "cd" command

Karl Auer
In reply to this post by Dr Rainer Woitok
On Wed, 2017-07-12 at 12:09 +0200, Dr Rainer Woitok wrote:
> By pure chance  I meanwhile happened to find a workaround.  Slightly
> changing your last two commands above yields
>
>    $ cd ../..//.three
>    $ pwd
>    /tmp/.three

I'll see that and raise you these (skip to the last eight lines of this
sequence for the finale(s)):

$ mkdir dottest                   
$ cd dottest
$ mkdir .one
$ cd .one
$ pwd
/home/kauer/temp/dottest/.one
$ mkdir .two
$ cd .two
$ pwd
/home/kauer/temp/dottest/.one/.two
$ mkdir .three
$ cd .three
$ pwd
/home/kauer/temp/dottest/.one/.two/.three
$ touch ../../../.one/fred
$ ls ../../../.one/fred
../../../.one/fred
$ ls -la ..
total 12
drwxrwxr-x 3 kauer kauer 4096 Jul 12 21:24 .
drwxrwxr-x 3 kauer kauer 4096 Jul 12 21:24 ..
drwxrwxr-x 2 kauer kauer 4096 Jul 12 21:24 .three
$ ls -la ../..
total 12
drwxrwxr-x 3 kauer kauer 4096 Jul 12 21:24 .
drwxrwxr-x 3 kauer kauer 4096 Jul 12 21:24 ..
drwxrwxr-x 3 kauer kauer 4096 Jul 12 21:24 .two
$ ls -la ../../..
total 12
drwxrwxr-x  3 kauer kauer 4096 Jul 12 21:24 .
drwxr-xr-x 22 kauer kauer 4096 Jul 12 21:24 ..
drwxrwxr-x  3 kauer kauer 4096 Jul 12 21:24 .one
$ cd ../../../.one
ksh: cd: /home/kauer/temp/dottest/one: [No such file or directory]
$ cd ../../../\.one
ksh: cd: /home/kauer/temp/dottest/one: [No such file or directory]
$ cd ../../../.one
ksh: cd: /home/kauer/temp/dottest/one: [No such file or directory]
$ cd ../../..//.one
$ pwd
/home/kauer/temp/dottest/.one
$ cd .two/.three
$ pwd
/home/kauer/temp/dottest/.one/.two/.three
$ cd "../../../.one"  
ksh: cd: /home/kauer/temp/dottest/one: [No such file or directory]
$ cd '../../../.one'
ksh: cd: /home/kauer/temp/dottest/one: [No such file or directory]
$ cd ../../../..one
ksh: cd: /home/kauer/temp/dottest/one: [No such file or directory]
$ cd ../../../...one
$ pwd
/home/kauer/temp/dottest/.one
$ cd .two
$ cd .three
$ cd /home/kauer/temp/dottest/.one
$ pwd
/home/kauer/temp/dottest/.one

So a double slash stops the dot being vanished by cd, starting at the
root does too, and three dots will be interpreted as one dot, but NOT,
further experimentation reveals, in all situations.

This is definitely violating the Principle of Least Astonishment in a
big way. I wonder if in the Korn Shell World (a strange and wondrous
place, little visited by me) there is a Grand Unifying Theory of Dots
that makes this all make sense.

This is from the ksh man page under "File Name Generation":

   If FIGNORE is set, then each file name component
   that matches the pattern defined by the value of
   FIGNORE is ignored when generating the matching
   filenames. The names . and .. are also ignored.
   If FIGNORE is not set, the character . at the
   start of each file name component will be
   ignored unless the first character of the
   pattern corresponding to this component is the
   character . itself.

It seems as if this could if we squint a lot) sorta kinda explain only
the dots in the last component of a path (the "file name") are ignored,
and why "..." is treated as ".", but it's still very weird.

Other areas of the man page indicate the ".." is special in some other
contexts too. Maybe those contexts are getting confused by cd?

This is interesting too:

$ x='cd ../../../.one'
$ echo $x         
cd ../../../.one
$ pwd
/home/kauer/temp/dottest/.one/.two/.three
$ cd $x
ksh: cd: bad substitution
$ cd "$x"
ksh: cd: cd ../../../.one: [No such file or directory]

Regards, K.
 
--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Karl Auer ([hidden email])
http://www.biplane.com.au/kauer
http://twitter.com/kauer389

GPG fingerprint: A52E F6B9 708B 51C4 85E6 1634 0571 ADF9 3C1C 6A3A
Old fingerprint: E00D 64ED 9C6A 8605 21E0 0ED0 EE64 2BEE CBCB C38B



--
ubuntu-users mailing list
[hidden email]
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
Xen
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Strange behaviour of the "cd" command

Xen
Karl Auer schreef op 12-07-2017 14:04:

> It seems as if this could if we squint a lot) sorta kinda explain only
> the dots in the last component of a path (the "file name") are ignored,
> and why "..." is treated as ".", but it's still very weird.

So no bug, but behaviour as intended, as expected.

To me it just seems like an esoteric problem because, .... (who uses
that thing?),

but yeah.

--
ubuntu-users mailing list
[hidden email]
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Strange behaviour of the "cd" command

Ralf Mardorf-2
On Wed, 12 Jul 2017 14:29:55 +0200, Xen wrote:
>To me it just seems like an esoteric problem because, .... (who uses
>that thing?)

BSD refugees?


--
ubuntu-users mailing list
[hidden email]
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Strange behaviour of the "cd" command

Joel Rees
In reply to this post by Karl Auer
On Wed, Jul 12, 2017 at 9:04 PM, Karl Auer <[hidden email]> wrote:

> On Wed, 2017-07-12 at 12:09 +0200, Dr Rainer Woitok wrote:
>> By pure chance  I meanwhile happened to find a workaround.  Slightly
>> changing your last two commands above yields
>>
>>    $ cd ../..//.three
>>    $ pwd
>>    /tmp/.three
>
> I'll see that and raise you these (skip to the last eight lines of this
> sequence for the finale(s)):
>
> $ mkdir dottest
> $ cd dottest
> $ mkdir .one
> $ cd .one
> $ pwd
> /home/kauer/temp/dottest/.one
> $ mkdir .two
> $ cd .two
> $ pwd
> /home/kauer/temp/dottest/.one/.two
> $ mkdir .three
> $ cd .three
> $ pwd
> /home/kauer/temp/dottest/.one/.two/.three
> $ touch ../../../.one/fred
> $ ls ../../../.one/fred
> ../../../.one/fred
> $ ls -la ..
> total 12
> drwxrwxr-x 3 kauer kauer 4096 Jul 12 21:24 .
> drwxrwxr-x 3 kauer kauer 4096 Jul 12 21:24 ..
> drwxrwxr-x 2 kauer kauer 4096 Jul 12 21:24 .three
> $ ls -la ../..
> total 12
> drwxrwxr-x 3 kauer kauer 4096 Jul 12 21:24 .
> drwxrwxr-x 3 kauer kauer 4096 Jul 12 21:24 ..
> drwxrwxr-x 3 kauer kauer 4096 Jul 12 21:24 .two
> $ ls -la ../../..
> total 12
> drwxrwxr-x  3 kauer kauer 4096 Jul 12 21:24 .
> drwxr-xr-x 22 kauer kauer 4096 Jul 12 21:24 ..
> drwxrwxr-x  3 kauer kauer 4096 Jul 12 21:24 .one
> $ cd ../../../.one
> ksh: cd: /home/kauer/temp/dottest/one: [No such file or directory]
> $ cd ../../../\.one
> ksh: cd: /home/kauer/temp/dottest/one: [No such file or directory]
> $ cd ../../../.one
> ksh: cd: /home/kauer/temp/dottest/one: [No such file or directory]
> $ cd ../../..//.one
> $ pwd
> /home/kauer/temp/dottest/.one
> $ cd .two/.three
> $ pwd
> /home/kauer/temp/dottest/.one/.two/.three
> $ cd "../../../.one"
> ksh: cd: /home/kauer/temp/dottest/one: [No such file or directory]
> $ cd '../../../.one'
> ksh: cd: /home/kauer/temp/dottest/one: [No such file or directory]
> $ cd ../../../..one
> ksh: cd: /home/kauer/temp/dottest/one: [No such file or directory]
> $ cd ../../../...one
> $ pwd
> /home/kauer/temp/dottest/.one
> $ cd .two
> $ cd .three
> $ cd /home/kauer/temp/dottest/.one
> $ pwd
> /home/kauer/temp/dottest/.one
>
> So a double slash stops the dot being vanished by cd, starting at the
> root does too, and three dots will be interpreted as one dot, but NOT,
> further experimentation reveals, in all situations.
>
> This is definitely violating the Principle of Least Astonishment in a
> big way. I wonder if in the Korn Shell World (a strange and wondrous
> place, little visited by me) there is a Grand Unifying Theory of Dots
> that makes this all make sense.
>
> This is from the ksh man page under "File Name Generation":
>
>    If FIGNORE is set, then each file name component
>    that matches the pattern defined by the value of
>    FIGNORE is ignored when generating the matching
>    filenames. The names . and .. are also ignored.
>    If FIGNORE is not set, the character . at the
>    start of each file name component will be
>    ignored unless the first character of the
>    pattern corresponding to this component is the
>    character . itself.
>
> It seems as if this could if we squint a lot) sorta kinda explain only
> the dots in the last component of a path (the "file name") are ignored,
> and why "..." is treated as ".", but it's still very weird.
>
> Other areas of the man page indicate the ".." is special in some other
> contexts too. Maybe those contexts are getting confused by cd?
>
> This is interesting too:
>
> $ x='cd ../../../.one'
> $ echo $x
> cd ../../../.one
> $ pwd
> /home/kauer/temp/dottest/.one/.two/.three
> $ cd $x
> ksh: cd: bad substitution
> $ cd "$x"
> ksh: cd: cd ../../../.one: [No such file or directory]

I have vague memories from college (thirty+ years ago), of one of
the popular shells having some odd behavior with the .. notations,
like ... being an abbreviation of ../.. or something.

Also, I have vague memories of dot itself being one of the pattern
matching characters in one of the shells, which induced ambiguities
that could be used for tricky stuff -- a definite misfeature.

Ultimately, some professors did not recommend csh for scripts. Too
many things you couldn't predict reliably.

ksh is a descendant of csh.

--
Joel Rees

One of these days I'll get someone to pay me
to design a language that combines the best of Forth and C.
Then I'll be able to leap wide instruction sets with a single #ifdef,
run faster than a speeding infinite loop with a #define,
and stop all integer size bugs with my bare cast.
http://defining-computers.blogspot.com/2017/06/reinventing-computers.html

More of my delusions:
http://reiisi.blogspot.com/2017/05/do-not-pay-modern-danegeld-ransomware.html
http://reiisi.blogspot.jp/p/novels-i-am-writing.html

--
ubuntu-users mailing list
[hidden email]
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Strange behaviour of the "cd" command

Dr Rainer Woitok
Joel,

On Thursday, 2017-07-13 06:59:58 +0900, you wrote:

> ...
> Also, I have vague memories of dot itself being one of the pattern
> matching characters in one of the shells,

No.  Dot is one of the  special characters  used in REGULAR EXPRESSIONS,
but not in SHELL patterns.

> ...
> Ultimately, some professors did not recommend csh for scripts. Too
> many things you couldn't predict reliably.

They were  perfectly right.   Just search  the web for  "Csh Programming
Considered Harmful".

> ksh is a descendant of csh.

No.   The descendant of "csh"  was called "tcsh".   The Korn Shell is in
fact Bourne Shell compatible in that you can run Bourne Shell scripts in
it, but whether this makes it a descendant of the Bourne Shell is debat-
able.   Just by its  name the Bash Shell  ("Bourne Again Shell") regards
itself a Bourne Shell descendant,  even though it added  plenty of feat-
ures already found in the Korn Shell.

Sincerely,
  Rainer

--
ubuntu-users mailing list
[hidden email]
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Strange behaviour of the "cd" command

Joel Rees
On Thu, Jul 13, 2017 at 6:54 PM, Dr Rainer Woitok
<[hidden email]> wrote:

> Joel,
>
> On Thursday, 2017-07-13 06:59:58 +0900, you wrote:
>
>> ...
>> Also, I have vague memories of dot itself being one of the pattern
>> matching characters in one of the shells,
>
> No.  Dot is one of the  special characters  used in REGULAR EXPRESSIONS,
> but not in SHELL patterns.

Heh.  My first year of using Unix, I couldn't remember whether I
was working in sed or the shell. Had to wait for Perl to finally figure
out regular expressions.

Still, I have this vague memory of a shell that tried to combine too
much of either sed or awk into its functionality -- not one of those
anyone remembers now. Might have actually been an alternative
(ahem) to MSDOS's command.com. Or I might have just been
confused. I spend a lot of my time confused.

>> ...
>> Ultimately, some professors did not recommend csh for scripts. Too
>> many things you couldn't predict reliably.
>
> They were  perfectly right.   Just search  the web for  "Csh Programming
> Considered Harmful".
>
>> ksh is a descendant of csh.
>
> No.   The descendant of "csh"  was called "tcsh".   The Korn Shell is in
> fact Bourne Shell compatible in that you can run Bourne Shell scripts in
> it, but whether this makes it a descendant of the Bourne Shell is debat-
> able.   Just by its  name the Bash Shell  ("Bourne Again Shell") regards
> itself a Bourne Shell descendant,  even though it added  plenty of feat-
> ures already found in the Korn Shell.

That's what they say, isn't it. There's another point of confusion. I keep
thinking "corn" instead of "David Korn's extension of Stephen Bourne's
shell with a lot of influence from csh".

--
Joel Rees

One of these days I'll get someone to pay me
to design a language that combines the best of Forth and C.
Then I'll be able to leap wide instruction sets with a single #ifdef,
run faster than a speeding infinite loop with a #define,
and stop all integer size bugs with my bare cast.
http://defining-computers.blogspot.com/2017/06/reinventing-computers.html

More of my delusions:
http://reiisi.blogspot.com/2017/05/do-not-pay-modern-danegeld-ransomware.html
http://reiisi.blogspot.jp/p/novels-i-am-writing.html

--
ubuntu-users mailing list
[hidden email]
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Strange behaviour of the "cd" command

C de-Avillez-2
In reply to this post by Dr Rainer Woitok
On Wed, 12 Jul 2017 12:09:01 +0200
Dr Rainer Woitok <[hidden email]> wrote:


> And as an aside, I also have a Korn Shell running on a Windows box
> under Cygwin which does NOT  exhibit the  strange behaviour
> described in this thread.   This one has a value of "@(#)MIRBSD KSH
> R54 2016/11/11" stored in shell variable "KSH_VERSION", making it
> considerably more recent.

For this one, you can install the mksh package; execute the shell by
calling 'mksh':

/data/buildd$ mksh
$ echo $KSH_VERSION
@(#)MIRBSD KSH R54 2016/11/11
$ ps
  PID TTY          TIME CMD
 4268 pts/4    00:00:00 bash
17069 pts/4    00:00:00 mksh
17318 pts/4    00:00:00 ps
$ ^D
/data/buildd$


Cheers,

..C..

--
ubuntu-users mailing list
[hidden email]
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users

attachment0 (817 bytes) Download Attachment
Loading...