ShareYourGroupShareYourGroupCommands

Windows commands

echo, set and PATH: variables in the Command Prompt

The Command Prompt keeps a set of named values called environment variables. They tell programs where things are: your user folder, the Windows folder, the temporary folder. echo prints text and the contents of variables, and set shows and changes them.

echo

Windows Command Prompt
C:\Users\asha\demo>echo Hello from the Command Prompt
Hello from the Command Prompt

echo prints whatever follows it. With > it writes that text into a file, and with >> it adds to the end of one. This is the quickest way to make a small text file.

Windows Command Prompt
C:\Users\asha\demo>echo First line > new.txt
C:\Users\asha\demo>echo Second line >> new.txt
C:\Users\asha\demo>type new.txt
First line 
Second line 

Danger. A single > replaces the whole file without asking. echo test > report.txt leaves report.txt holding only the word test. Use >> when you mean to add.

Variables

A variable is written between percent signs. Windows sets up many of them when it starts.

VariableHolds
%USERNAME%your account name
%USERPROFILE%your user folder
%COMPUTERNAME%the name of the computer
%TEMP%the folder for temporary files
%WINDIR%the Windows folder
%CD%the current folder
%DATE%, %TIME%the date and time now
%PATH%the folders searched for programs
%RANDOM%a random number from 0 to 32767
Windows Command Prompt
C:\Users\asha\demo>echo I am in %CD%
I am in C:\Users\asha\demo

They work in any command, not only in echo. cd %USERPROFILE% goes to your user folder, and cd %TEMP% to the temporary folder.

set: your own variables

Windows Command Prompt not run here
set city=Ludhiana
echo I live in %city%

The second line prints I live in Ludhiana.

Do not put spaces round the equals sign. set city = Ludhiana creates a variable whose name ends in a space.

set on its own lists every variable. set P lists those whose names begin with P.

A variable made with set lasts only until that Command Prompt window is closed, and exists only in that window.

Asking a question

set /p waits for the user to type something and stores it. Batch files use it for simple prompts.

Windows Command Prompt not run here
set /p name=What is your name?
echo Hello, %name%

Arithmetic

set /a works out whole-number sums.

Windows Command Prompt
C:\Users\asha\demo>set /a total=250*4+18
1018

PATH

When you type a command such as notepad, Windows does not search the whole disk. It looks in the current folder and then in each folder listed in the PATH variable, in order. If the program is in none of them, you see:

Windows Command Prompt
C:\Users\asha\demo>nosuchprogram
'nosuchprogram' is not recognized as an internal or external command,
operable program or batch file.

That message does not mean the program is missing from the computer. It means it is not in a folder on the PATH.

To see the PATH:

Windows Command Prompt not run here
echo %PATH%
path

It is a long line of folders separated by semicolons.

Which program will run?

where shows the full location of the program that a command would start. It is the way to find out which copy runs when several are installed.

Windows Command Prompt not run here
where notepad
where python

If where finds nothing, the program is not on the PATH.

Adding a folder to PATH

For the current window only:

Windows Command Prompt not run here
set PATH=%PATH%;C:\Tools

For good, use the settings screen: search the Start menu for "environment variables", choose Edit environment variables for your account, select Path, click Edit, then New, and add the folder. Open a new Command Prompt afterwards, since windows already open keep the old value.

Danger. The command setx PATH "%PATH%;C:\Tools" is often suggested online for a permanent change. It can cut a long PATH short, losing entries, and it mixes the system's list into your own. Editing through the settings screen is safer. Before any change to PATH, copy its current value into a text file so that you can put it back.

A first batch file

A batch file is a text file of commands, with a name ending in .bat. Running it runs the commands in order.

Windows Command Prompt not run here
@echo off
echo Today is %DATE%
echo You are in %CD%

Save those three lines in Notepad as hello.bat, and type hello to run them. @echo off stops the commands themselves from being printed, leaving only their output.

Danger. Never run a .bat file from an email or a website unless you have opened it in Notepad and understood every line. A batch file can delete files as easily as it can list them.

Clearing the screen

cls clears the window. title Something changes the text in the window's title bar, and color 0A changes its colours.

On Linux and the Mac, see echo, variables and PATH.

Examples shown with output were run on 12 November 2026 in a practice folder: Windows commands in cmd.exe on Windows 11, Linux commands with the GNU tools of Git Bash. The folder path and user name were replaced with made-up ones. Commands marked "not run here" are shown as you would type them.

This is an independent learning site. It is not connected with Microsoft, Apple or any Linux distribution. Windows, macOS and other names belong to their owners. Try commands first in a practice folder, never on files you cannot afford to lose.