-2

I need somebody to explain me what is happening in this sequence of "cd.." commands (note there is no space between "cd" and "..") :

c:\sebas\miscosas\escacs\pgns\$_ya\2018_08_sants>cd..

c:\sebas\miscosas\escacs\pgns\$_ya>cd..

c:\sebas\miscosas\escacs\pgns>cd..

c:\sebas\miscosas\escacs>cd..

c:\sebas\miscosas>cd..
'cd..' is not recognized as an internal or external command,
operable program or batch file.

I did write "cd.." just once, and later I use "arrow up" to recover previous command.

Why is it failing on 5-th time ?

The OpSys is Windows Server 2008 R2, version 6.1, build 7601.

Thanks

By the way, if I use "cd .." (with a space between "cd" and ".."), then all goes fine.

Ross Ridge
  • 38,414
  • 7
  • 81
  • 112
Sebastia.Net
  • 129
  • 2
  • 14

1 Answers1

-1

cd.. is wrong syntax and works just by chance.

The right syntax is: commandSPACEargument

The command is cd and the argument is the relative path ..\.

But cmd.exe searches first for a file with name cd on using cd.. because it interprets cd.. as mistyped file name and not as internal command CD. And Windows command processor tries to run found file when there is in current directory really a file with name cd as it is obviously the case for directory c:\sebas\miscosas.

The two dots at end of cd.. are removed by cmd.exe on searching for a suitable directory entry. Removing trailing spaces/tabs and trailing dots is nearly always done as part of an error correction as it can be seen on running the command line:

echo Hello world!>"cd..  "

This command line creates a file with name cd without the two dots and the two spaces at end.

See also DosTips forum topic ECHO. FAILS to give text or blank line - Instead use ECHO/ which is about the same issue.

And see also Microsoft article about Naming Files, Paths, and Namespaces.

The usage of cd..\ works even if there is a file with name cd in current directory. But this command line is nevertheless using wrong syntax and works again only by chance. If there would be a file with name cd. in current directory, this command line would fail again because of cmd.exe searches now for a file with name cd. in current directory.

So in future use command CD only with right syntax: cd ..\

Mofi
  • 46,139
  • 17
  • 80
  • 143
  • CMD reads up to the first delimiter not space alone to get the command. See `dir/a/b`. `dir.` and `dir..`. – CatCat Sep 24 '18 at 08:31
  • @CatCat That's true, but `.` is not an argument separator for Windows command processor. Horizontal tab (0x09), vertical tab (0x0B), form-feed (0x0C), normal space (0x20), comma (0x2C) semicolon (0x3B), equal sign (0x3D) and no-break space (0xFF in OEM code pages) are argument separators as written by Dave Benham in [How does the Windows Command Interpreter (CMD.EXE) parse scripts?](https://stackoverflow.com/a/4095133/3074564) I am quite sure that nobody typing commands in command prompt window uses intentionally any other argument separator than normal space. `cd..` is definitely wrong. – Mofi Sep 24 '18 at 09:04
  • @CatCat `dir/a/b` is also of wrong syntax. Windows command processor interprets `/` first as beginning of an option and therefore auto-corrects and interprets it as `dir /a /b`. But forward slash could be also interpreted as directory separator within a file/folder argument string. That does not happen on usage of `dir/a/b`, but it is no advisable to run commands on which `cmd.exe` needs to auto-correct the syntax as in some use cases the auto-correction could result in an execution behavior not expected by the user as the `cd..` example demonstrates. – Mofi Sep 24 '18 at 09:13
  • I use `command/?` all the time. Forward slash to backslash is done last and recently added. Type `cd\\`. Dave whoever is not 100% right. – CatCat Sep 24 '18 at 09:19
  • And it is not advisable. Rules only seem to apply to switches and command name only. Subsequent parameters must act normal except switches. – CatCat Sep 24 '18 at 09:21