6

When writing Batch files (.bat), ECHO. is used to print a blank line to the screen.

How does this work? What is the significance of a . after the command name?

From the tests below, it seems that executing a command like PROMPT. is identical to executing PROMPT .. Why is this the case?


The outcome of executing various commands with a dot following the command name:

ECHO.        prints blank line
DIR.         lists current directory (as if no dot is present)
EXIT.        exits
HELP.        command not found
VER.         prints windows version (as if no dot is present)
CD.          does nothing (contrary to `CD` which prints the current directory)
CLS.         clears the screen  (as if no dot is present)
VOL.         "The system cannot find the drive specified."
SET.         "Environment variable . not defined"
TYPE.        "Access is denied."
PATH.        changes %PATH% to .
SHUTDOWN.    command not found
PROMPT.      changes the prompt to .
TITLE.       changes the title to .
3

This approach is also used in situations where it is not known whether the line will be blank or not, such as when an environment variable or replaceable argument is being displayed, but could be empty, as in ...

echo.%1

or

echo.%SomeVar%

Source:

  1. "echo." command in CMD.EXE
  2. What does ECHO .> mean in batch file?
1

I think you've answered your own question...

The full stop is an argument with different outcomes. For the ECHO command it's a way of putting a blank line (without the . you get the status of the session variable) in that case. Maybe you can find some hidden commands with using that :D

0

Well I know the explicit answers for some of these.

For instance CD

By itself CD prints the current directory this is True.

However ., .., and ( \ or / ) have special meaning to CD.

For ., CD expands . to be "Drive:\Path\Current_Folder", it then acts on this and "changing" you to the same directory you were already in.

For .., CD expands .. to be "Drive:\Path\Parrent_Folder", it then acts on this and changing you to the parent directory of the folder you were in.


For /, CD treats this as a switch if the next character is D or ? D is used to change drives, and because it could be a valid directory on the root of the drive it would break if you use it as the first character in order to reach that folder.

So if you have a directory on the root that is the letter D (eg C:\D\ ) you can not change to it, or any given subdirectory of it (eg C:\D\E) using CD /D or CD /D/e to reach it, as this is also the switch to change drives.

Instead you can use CD \D or CD C:/D or CD \D/e to change to it or it's sub directories from anywhere.


For both For \and /, other than as mentioned above, CD treats it as a separator between steps to execute, and acts on each step in series. from here out I'll just refer to \ but remember that / can be used interchangeably other than the caveat above.

ie CD will chunk it's actions by looking at each segment and acting on it with the \ acting as separators.

eg CD C:\Windows\System32\Drivers\etc is acted on by CD as CD C:\ & CD Windows & CD System32 & CD Drivers & CD etc

If CD finds \ is the first character other than white-space to follow the command, it expands it to be the root of the drive (eg CD \ expands to CD C:\).

SO CD \WindowsSystem32\Drivers\etc expands to the same CD C:\ & CD Windows & CD System32 & CD Drivers & CD etc

C:\Windows>CD C:\ & CD Windows & CD System32 & CD Drivers & CD etc

C:\Windows\System32\drivers\etc>CD \windows

C:\Windows>CD \Windows\System32\Drivers\etc

C:\Windows\System32\drivers\etc>

Because it is essentially treating the provided directory path as a series of CD commands which can be executed, you can treat it like a script where you CD to many directories one at a time, and utilize .. to go up any number of directories, and while you can use . it isn't of much use per-se

So to recap, CD . changes to the current directory CD .. changes to the parent directory, CD ./subdirectory or CD subdirectory changes to that sub directory, CD \ changes to the root of the drive, CD \Windows\System32 Changes to a path along the root.

What if you are in C:\Windows\System32 and want to go to C:\Windows\System ? Well you could just do CD C:\Windows\System but what if you have some long path and you just want to move over to a different sibling directory of the parent without re-typing or copy and pasting? here is where the serialized nature of CD comes into play!

You can reach the sibling directory by 1st instructing CD to move back to the parent directory using .. and then down to the sibling directory.

C:\Windows\System32>CD ..\System

C:\Windows\System>

You can also move back multiple parent directories by separating .. from another .. with a \

C:\Windows\System32\drivers\etc>CD ..\..\..

C:\Windows>

You can also do strange things like move backwards and forwards in the folder tree using multiple .. at different parts or write terms in there of a single . whcih just move you to the same directory over and over

eg:

C:\Windows\System>CD ..\System32\.\.\.\Drivers\etc\..\.\etc

C:\Windows\System32\drivers\etc>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.