Basic Windows Batch Tutorial
by kinglarry II in Circuits > Computers
597 Views, 0 Favorites, 0 Comments
Basic Windows Batch Tutorial
hello guys, in the matter of 24h I published a windows batch tutorials I promised u in my last instructable. if u haven't seen it click on this link here: https://www.instructables.com/id/Python-Tutorial/
this is on the very(x100) basics of batch programming. this is for total beginners. do not even hesitate to look at this if ur a pro already. Although, it might be nice of u to get my views up :p
so, to find batch, find the search menu and type in notepad. this is where u will be writing ur script. technically, we could call this a new window, because, like in other programming languages, there is always a new window for people to write in and they execute the command in the shell which im going to show u.
to access the 'shell' type in the search bar 'cmd' that is short for command prompt. this is usually used by users to ask the computer to do something like ban a user or download a application. but today, we're going to use it for programming purposes.
Try These Out....
these are some of the basic commands that we will be using:
echo *something* - does what it sounds like echos it. try this in cmd type echo Hello World. iconic programmer's beginner script. im not a beginner, but I still say it
cls - clears the page. test it. in cmd, type a load of random stuff, then enter then do it again for about another 3 million times, then type in cls then everything will disappear
C:\users> ergehoeiboegboieghoimythgiuheuhon4jht4phnn
C:\users> rwiheiuybgviugebvrgvbhgbrovuogvihbghbohrbhw
C:\users> ljehfbocubeuohboubgyunrechongrcenogrcho
C:\users> cls
------------------------------------------------------------------------------------------------------------------------------------------------------
C:\users>_
@echo off - this will turn off the C:\users> headcases that I find very annoying. I wish I could get rid of the '>>>' in python as well.
goto - very useful in loops. this will direct the user to a different part of the universe (sorry I got carried away), I mean, script.
start - it starts something. start cmd will start cmd. BTW start and goto are a very dangerous combination. im not here to teach u how to commit computercide, but never put the start command in a loop.
pause - this will pause it and it will come up with Press any key to continue...
bit long...
Ur First Program.
this program will count to 1000. please try to type it rather than copy and paste so u could understand it better:
@echo off
set /a x=1
:top
set /a x=%x%+1
echo %x%
if %x%==1000 goto exit
goto top
:exit
cls
pause
exit
set /p input= - not in this script, but gives an input variable from the user.
set /a x=1 - sets an integer variable so that x=1
%x% - referring to the variable we set earlier. when we write that, the computer will know that we mean '1'
== - it means DOES equal. confirms the equation.
so, there we are, ur first program!
please send this to me via did u make this project.
Input & Output
very simple. I showed u the command in part 2. write this program and learn from the output.
@echo off
color 2f
:top
cls
echo good day
echo what is ur name?
set /p input=
cls
echo hello %input%, how are u doing?
echo would u like to continue? (y/n)
set /p ans=
if %ans%==y start www.instructables.com
if %ans%==n goto confirm
if %ans% neq y goto sorry
if %ans% neq n goto sorry
:confirm
cls
echo are u sure u want to leave? (y/n)
set /p ans=
if %ans%==y exit
if %ans%==n goto top
:sorry
cls
echo i'm sorry, but I don't understand what u mean.
echo continue? (y/n)
set /p ans=
if %ans%==y goto top
if %ans%==n goto confirm
neq - does NOT equal
if ur still here , welldone for keeping up.
Time and Date
these variables are already set by cmd.
C:\Users>echo %time%
9:16:25
C:\Users>echo %date%
2018/8/22 Wednesday
this is ur task if ur feeling like a pro now, try create a clock with the output like the image.
this is it ! if ur a beginner, u are now not! Congratulations!
Do remember to put the images of the programs in did u make this project.
Done
I will definitely publish more content later on.
if u want to learn more batch, I recommend basic batch programming by seJma
here are a few programs I made, I should definitely recommend that u try to make them
the maths game will never crash, no matter what u type in it.
the fish one is the dangerous computer crusher thingy that I recommend u not to run. u can put it into a usb so u can stop the program
the site selector is incredibly easy to make, just get ur labeling and website urls right!
all right, so that's it!