Tuesday, 24 February 2015

Command Line Scripting Tutorial Series Part 3 # Variables.

Command Line Scripting Tutorial Series
(Part '3') # Variables



Hi Everybody, It's The Third Tutorial Of Command Line Scripting Tutorial Series, And In This Third Tutorial We Are Gonna Learn About Variables And Variables In Command Prompt, First Of All Let Me Tell You What Really A Variable Is.

Variables: Why Variables Are Used ?, Well Variables Are Used To Store Data In It And Variables Are Differently Named By User(s) So You Can Call A Particular Variable To 
Store Data In It Or Get Data You Stored In It.

Variables In Command Prompt: Variables Are Same In Every Language(s) They Does The Same Job In Every Language(s), The Only Difference Is The Syntax And The Method Of Declaring A Variable, In Command Prompt A Variable Is Declared By Using 'Set' Command And The Syntax Is (Set Variable_name = Variable_value) For Example : Age = 17, And In Command Prompt A Variable Is Called By Using '%' For Example : Echo %Age%.

Example Of Using Variables In Command Line Script: Now We Are Going To Make A Script That Use Variable In It. Make A New Cmd/Batch File, Edit It And Type The Following Code.

@echo Off
title Using Variables
set Greet="Hi Nice To Meet You !"
cls
echo %Greet%
pause

Taking Input From The User: You Can Even Take Input From User But For That You Have To Store The Data That User(s) Gives To A Temp Directory To Process It, And That Is Where's Variables Comes Handy, For Taking Input From User And Storing It To A Variable We Are Gonna Use 'Set' Command With "/p" Parameter, The "/p" Parameter Tells The Command Prompt That We Are Taking Input From The User, Well The Syntax Of This Command Is (Set /p Variable=[promptString]) For Example: Set /p Name="Enter Your Name Please:".

Example For Taking Input From The User: Now We Are Going To Make A New Script For Taking Input From The User And Store It To A Variable And Then We Are Going To Call The Variable To Display The Value Which User Gives. Now Make A New Cmd/Batch File And Type The Following Code.
@echo Off
title Taking Input
set /p Name="Hi, Enter Your Name Please: "
cls
echo Nice To Meet You, %Name%
pause


OK, That's Enough For Today See You Guys Tomorrow With The Next Tutorial Of Command Line Scripting Tutorial Series.


Thanks For Visiting.
Hope It Helps, If It Then Please Share.
Stay Connected For More Updates.
If You Got Any Question Or Problem Or Want Me To Make Tutorial On Something Then Please Just Let Me Know.



No comments:

Post a Comment