Line At A Time
Level 16: Your First Batch File
Your First Batch File Teach the computer a command of your own.

A file ending .BAT is a batch file: a list of MS-DOS commands that run one after another, which is exactly what a bash script is. Batch files are how a computer of this era was taught to do anything by itself, and the AUTOEXEC.BAT sitting at the top of this disk is the one DOS ran every time the machine started. TYPE it and see.

You already know how to make a file: ECHO with > to start it and >> to add to it. That is all a batch file needs.

The first line of nearly every batch file is @ECHO OFF, which means "do not print each command as you run it, just do it". The @ hides that line itself. Watch out for the double ECHO on the second line: the first is the command doing the writing, the second is the word being written INTO the file, ready to run later.

Then type the file's name without the .BAT to run it. MS-DOS makes no distinction between its own commands and yours: you have just added a new command to this computer.

ECHO @ECHO OFF > HELLO.BATStart the batch file.
ECHO ECHO Hi there! >> HELLO.BATAdd the line it should run.
TYPE HELLO.BATRead your program back.
HELLORun it.
Your task
  • Create HELLO.BAT with at least two lines in it
  • Read it back with TYPE
  • Run it by typing its name

Open this level in your browser to type the commands at a live terminal that answers back.