How to Write a Script to Run in Command Line
If you want to automate mundane tasks that need frequent repeating, you can write scripts to run from the command line. In Windows, these are called batch scripts (with a .bat extension). Batch scripts are plain-text files that contain simplified commands. You can do a large number of things with batch scripts once you know how to program them. Batch scripts can be fun to learn to use and require a lot of experimentation depending on what you need them to do. You can write batch scripts to run in the command line using built-in Windows software.
Instructions
-
-
1
Click "Start," then type "notepad" and hit "Enter." Notepad is a plain text editor built in to Windows.
-
2
Type "@echo off" and press "Enter" (quotation marks should not be typed throughout). This is a standardized line at the start of your script to stop other scripts from running before it.
-
-
3
Type "rem first script" and press "Enter." "Rem" is a comment line, which means it is ignored by the script processing. Use "rem" commands to help organize your scripts. You can also type ":: comment here" for the same effect. Double-colons, like "rem" indicate a comment.
-
4
Type "echo Hi there" and press "Enter." "Echo" is a command that displays text; in this case "Hi there" will be displayed.
-
5
Type "Pause_" and press "Enter." "Pause_" will stop the batch script from automatically closing. This is useful when creating your scripts but you will want to remove it afterward.
-
6
Click "File," then "Save As." Click the "File type" drop-down menu and select "All FIles and Folders." Designate a location for your file, then save it as "myfirstscript.bat" or similar. Click "Start," then type "cmd" and press "Enter." Change the directory using "cd" to navigate to your directory with the script in and type "myfirstscript.bat" and press "Enter." Your script will run. You can also double-click this file in Windows to make it run.
-
1