5

Why does this work?

if [ -d "." ] ; then echo "ok"; else echo "nok"; fi
if [ -d ".." ] ; then echo "ok"; else echo "nok"; fi
if [ -d "..." ] ; then echo "ok"; else echo "nok"; fi
if [ -d "...." ] ; then echo "ok"; else echo "nok"; fi
if [ -d "nosuchdir" ] ; then echo "ok"; else echo "nok"; fi

Output:

ok
ok
ok
ok
nok

What is supposed to mean ... or .... in a shell env?

codeforester
  • 39,467
  • 16
  • 112
  • 140
Ozh
  • 719
  • 1
  • 7
  • 20

1 Answers1

8

It means someone has created directories named ... and ..... Consider:

$ [ -d '...' ] && echo 'ok' || echo 'nok'
nok
$ mkdir ...
$ [ -d '...' ] && echo 'ok' || echo 'nok'
ok
bishop
  • 37,830
  • 11
  • 104
  • 139
  • 6
    ...unless the OP has badly mistagged their question and is actually running "Git Bash" or such on Windows, in which case `...` is equivalent to `../..`. – Charles Duffy May 19 '17 at 20:07
  • 2
    @CharlesDuffy This feature was incorporated into Windows 95 from Novel NetWare. It was not included into the Windows NT branch. So it has been more than ten years since the feature was last time in a supported Windows version (probably Windows ME). --- See https://devblogs.microsoft.com/oldnewthing/20160202-00/?p=92953 https://superuser.com/questions/480122/does-have-meaning-as-a-relative-pathname-edit-no#comment568496_480122 – pabouk - Ukraine stay strong Dec 16 '19 at 12:25