BATCH FILES

3 0 0
                                        

Ok,
Recently I have been learning batch or .bat
It is pretty simple to get the jist
So let's start with how I/most will start a batch script
@echo off
:start
@echo hi
Goto start
This, when ran will just say hi extremely quickly in command prompt. Note you will not be able to input anything.
Let's break it down, shall we?
So @echo off means it will not repeat commands like goto start. If it is on, it will look like this;
Hi
Goto start
Hi
Goto start
That's what it would look like if it was on (it's on by default)
Next is :start this basically does nothing, I think of it like a bookmark if a goto command says to goto start it will go there. I do not know what would happen if you had multiple :start.
Then @echo (TEXT) will just display that text in cmd.

So wanna get into variables and user input? This took me the longest to get used to
So let's start with another sample code
@echo off
:start
Set /p
If "%a%"=="yes" goto Wrong
If "%a%"=="YES" goto wrong
If "%a%"=="no" goto ok
If "%a%"=="NO" goto ok
:wrong
@echo LIAR!!!
Pause
Goto end
:ok
@echo well get one
Pause
:end

Ok, so, let's break this down! Yaaaaaaayyyyyyyyyyy! Note the sarcasm!
So the set /p (variable here)="(txt to be displayed)"
I know it basically makes 'A' a variable but I don't know it's exact function. But if you use /a it will not ask for your input so that man be something.
Just a note! When you refer to 'A' as a variable do %A% some commands will want it in speech marks eg; the if command which we get to break down
If "%(variable)%"=="(whatever it is set to) goto end
This it will go to the end if the result is true. Eg; A=3
If "%a%"=="4" goto end
It would not go to the end.
NOTE IT IS PICKY WITH CAPS
Wanna make a calculator? I have but I will assign you the task to design your own!
I will give you the last segment required to make a calculator (in command prompt)
Set /a "%result%=%a%+%b%"
@echo. %result%
You need to put a full stop after echo like it is, no space separating it!
Also it works like algebra but it isn't YOU CANT GIVE IT L+N or something like it. The variables need to be numbers and multiply is * and divide is / for computers if you didn't know eg;
%A%=10
%B%=L

Set /a "%result%=%A%*%B%"
@echo. %result%
Result=10
If a variable= a letter then it is classified as 1 in calculations
Please privately message me your finished calculator. It is EXPECTED to have add, subtract, multiply, divide!
Another useful command is start
Start (file location) then put a \(file name)
Eg;
C:\\user\desktop\
At the end of that add the file name
Eg;
@echo off
:start
Start (location not shortcut)\Minecraft.exe\
Goto start

Have fun with that command up there? I wouldn't 100's of MC launchers a second

How was my tutorial for batch? Please comment!

Has llegado al final de las partes publicadas.

⏰ Última actualización: Sep 12, 2017 ⏰

¡Añade esta historia a tu biblioteca para recibir notificaciones sobre nuevas partes!

Random stuff + why I don't upload muchDonde viven las historias. Descúbrelo ahora