Gettng-Started | Coach Beard Jr. Boring Notes (2024)

Introduction

Series of command that is executed by CLI, extension is ".bat" or ".cmd"

echo -> used to output some data to the terminal/user pause -> will pause the process for user input and then after some input then window closes.

Command Echoing -> all the commands executed or written in a file are displayed in the terminal and are executed one by one with output. By default it is on To turn off this feature use @Echo off or Echo off

Now if the feature is turned off you can only see the output of the command execution...

@Echo off -> will not display the "Echo off" output also Echo off -> it will display "Echo off" first then the output of the commands

VER -> Displays the os version

CD -> navigate to working directory, if no extra arguments are given then it will print the current working directory path from root folder.

CHOICE -> will prompt the user to select an option from the list of options using single character If no input is given, then it will consider the default value

CHOICE /C <OptionsWithoutAnySpaces>

Ex: choice /c ABCD /m "Displaying this message and user will have four options to select from A,B,C,D"

Date -> display current system date Time -> display current system time

use %variable% syntax to echo variables

TASKLIST -> will list a currently running process on the system that was executed on, it also displays the PID, Memory Usage, Name and Session Number information also for each process

@REM -> comments in a batch script file

COMP -> compare two files comp file1 file2

COPY -> copy [source] [destination] copy the contents of source to destination, if no destination path is mentioned then the current working directory is considered as destination This will copy only files but not the folders/directories, for this we can use XCOPY command

XCOPY -> xcopy [source] [destination] /S copies all the files and folders except sub directories. /E -> copies empty directories also to destination folder

MOVE -> move [source] [destination] move content from source to destination, can be used to rename files/folders

ATTRIB -> Displays or changes file attributes. Usage: ATTRIB [+R | -R] [+A | -A] [+S | -S] [+H | -H] [+O | -O] [+I | -I] [+X | -X] [+P | -P] [+U | -U] [drive:][path][filename] [/S [/D]] [/L]

+ Sets an attribute. - Clears an attribute. R Read-only file attribute. A Archive file attribute. S System file attribute. H Hidden file attribute. O Offline attribute. I Not content indexed file attribute. X No scrub file attribute. V Integrity attribute. P Pinned attribute. U Unpinned attribute. B SMR Blob attribute. [drive:][path][filename] Specifies a file or files for attrib to process. /S Processes matching files in the current folder and all subfolders. /D Processes folders as well. /L Work on the attributes of the Symbolic Link versus the target of the Symbolic Link

Special Characters

@ -> lets batch processor know to be less verbose :: -> comments in batch file > -> redirects the command output to mentioned next action, might to send output to terminal or to another command or just store it in another file, this will overwrite the already present data that was present in file >> -> appends the output to already present data in the file

We can capture the command line arguments using %[number]

echo enter 2 argumentsecho %1echo %2

test.bat hi MOM -> this outputs the arguments "hi" and "MOM" to console and they are retrieved by their position

SET -> set [key]=[value] define variables using this keyword variable names are not case sensitive

set str='Hi MOM' :: str is variable name and "Hi MOM" is the content of variableset abl = another one :: "abl " is the variable name and " another one " is the content of the variableset /A number=20 :: the variable holds the numeric value, any fraction value will be rounded to nearest integerset /P userInput="Enter input" :: asks user for input and stores it in this variable

By default all variables are global variables, any variables that are defined between SETLOCAL and ENDLOCAL are considered local scoped variables

set gloablVar="Global"setlocalset localVar='local'echo %localVar%endlocalecho %globalVar%

Environment variables are available globally and can be directly accessed by %envVariableName%

  • %var% -> this is instruction as get the var value at the compile time

  • !var! -> this is instruction as get the var value at the run time

Gettng-Started | Coach Beard Jr. Boring Notes (2024)
Top Articles
Latest Posts
Article information

Author: Francesca Jacobs Ret

Last Updated:

Views: 6546

Rating: 4.8 / 5 (68 voted)

Reviews: 91% of readers found this page helpful

Author information

Name: Francesca Jacobs Ret

Birthday: 1996-12-09

Address: Apt. 141 1406 Mitch Summit, New Teganshire, UT 82655-0699

Phone: +2296092334654

Job: Technology Architect

Hobby: Snowboarding, Scouting, Foreign language learning, Dowsing, Baton twirling, Sculpting, Cabaret

Introduction: My name is Francesca Jacobs Ret, I am a innocent, super, beautiful, charming, lucky, gentle, clever person who loves writing and wants to share my knowledge and understanding with you.