Basic Batch Command List

About: I'm kid that bumped into batch file coding and made lots of effort to learn every thing to make text based games, at least until someone told me that there is more than Batch, then I tried to learn C++, but ...

Echo off (Stops displaying c:> before every line of code displayed in the command prompt.)

Example:Stops displaying c:>

Echo off

Echo (Displays a message on the command prompt.)

Example: Displays "Hello world".

Echo Hello world!

Title (Sets the the command prompt title.)

Example: The title is now "Greeting the world".

Title Greeting the world

Cls (Clears all text above and does not display Cls)

Example: Displays "Hello world" then Displays "Bye" With nothing above Bye.)

Echo Hello world
Cls
Echo Bye

Pause (Pauses the code until a key on the keyboard is pressed and displays " Press any key to continue...".

Example:

Echo Hello world
Pause
echo Bye

Color (Sets the color of the text and background. The first digit is the background the second digit is the text.)

Example: 0 is the background A is the text.

Color 0A

Set (Sets a variable.)

Example: "Name" now equals "Bob".

 Set Name=Bob

If (Condition for a variable.)

Example: If the variable "Name" is equal to Bob then it will display "Welcome, Bob" on the command prompt.

If %name%==Bob Echo Welcome, Bob

If not (Condition for a variable.)

Example: If the variable "Name" is NOT equal to Bob then it will display "Your not Bob" on the command prompt.

If not %Name%==Bob echo Your not Bob

Exit (Closes the command prompt)

Example: Closes the command prompt after the pause.

Echo Hello world
pause
cls
Echo Bye
pause
exit

: (A series of code title)

Example: The class is called "Start" and executes all the commands below it.

:Start
Echo off
Title Are you Bob?
Color 0A
Set Name=Bob
If %Name%==Bob echo Welcome, Bob
If not %Name%==Bob echo Your not Bob
Pause
Cls
Echo Bye
Pause
exit

Set /a (Sets a variable with a math equation.)

Example: The variable "Number" equals 2.

Set /a Number=1 + 1

Set /p (Asks for user input.)

Example: Displays "What is your name:" and the variable "Name" set to equal whatever you type into the command prompt.)

Set /p Name=What is your name:

Start (Will open a program on your computer or open a Link)

Example 1: Opens up Google Chrome the program.

Start Chrome.exe

Example 2: Opens the link to instructables the web site you are on right NOW.

Start "https://www.instructables.com/"

2 People Made This Project!

Recommendations

  • Toys Contest

    Toys Contest
  • PCB Contest

    PCB Contest
  • First Time Author

    First Time Author

5 Discussions

0
None
Mr_ MikaS

2 years ago

I'm sorry, I don't see any space.

0
None
NicoFilippo

2 years ago

How can I make a BATCH program solve a math problem with preset formula?

For Example: You enter 3 and using formula S=3,1*d (*= times, d=the set number, so in this example 3) and you get the result? Please, help urgent...

0
None
Mr_ MikaSmohab.mohamed.9404

Reply 2 years ago

Try using @start instead of start.

@start allows there to be %variables% in it.