Arguments

You have typed in a few commands now, and some of those commands took additional information such as a file name. The additional pieces of information you type after a command name are called arguments, or synonymously in most contexts, parameters.

In Command Prompt, arguments are separated by spaces. When you type cd .. for example, Command Prompt splits the text you typed by spaces. The first piece of text is always taken as the command name. Every piece of text after that is taken as an argument. The argument is passed in a list to the internal programming of the command. If you ever write software or scripts, you will eventually learn how to get this list of arguments too.

Try typing help cd again. You will see something like:

Displays the name of or changes the current directory.

CHDIR [/D] [drive:][path]
CHDIR [..]
CD [/D] [drive:][path]
CD [..]

The above is documentation that Command Prompt users learn how to read. The CHDIR lines are telling you that CHDIR is another name for CD. More importantly, notice the argument [..]. The brackets usually mean the parameter is optional. But what is ..? If you read down, you’ll see:

.. Specifies that you want to change to the parent directory.

This help documentation is telling you that you can optionally type .. as an argument and it will work.

Now take note of the optional /D argument. What does that do? Well read down and you’ll see:

Use the /D switch to change current drive in addition to changing current directory for a drive.

Now we know! You can specify /D as an argument to switch from C:\ to D:\ or E:\ or wherever you may need to. This is useful if you want to change your working directory to a USB flash drive. Example: cd /D "X:\Travel Files".

Spaces

To force Command Prompt to ignore spaces and treat text as a single argument, put quotes around the argument. That is why you need quotes around file and folder names containing spaces.

Switches

Arguments such as /D above are often called switches. The argument can be thought of as switching an option on/off. File name arguments are not switches. You’ll often see switches start with a forward slash /, but sometimes a hyphen - or double hyphens -- too.

Switches typically are case insensitive. For simple commands, a good programmer should have remembered to check for both capitalized and lowercase arguments while looking at the argument list. Some very complicated programs have so many switches that they need capital and lowercase letters to be different things. Some programs are complicated enough to abandon the one-letter convention and use full words for switches.

Don’t be surprised to see variation. If you glance at the documentation you’ll be okay.

Help

Most commands will not have help text with HELP. Programmers typically include documentation inside their command, which you can access with the right arguments.

If you are stuck and want to see documentation, try specifying /? as an argument. For example, enter cd /? and you will see the same text help cd gave you. Some programmers use /h or -h to give help text instead.

Feel free to try these arguments for new commands. If you’re worried about what might happen when they don’t work, check online first. Testing unknown arguments in cd or dir might be harmless, but you would be a smart person to think twice before seeing how shutdown handles shutdown /?. For the record, shutdown /? does give you help documentation instead of shutting down your computer.


Prev ————————– Next

Leave a Reply

Your email address will not be published.