This lesson we are going to define variable and Rondo's variables.
So this is a good exercise where you will learn how you could define variables at the beginning of the
script.
So any way you would need to use those variables anywhere in the scrap metal or the end you could just
simply run that container that variable.
So what exactly a variable is.
So let's look at.
So look at this list that I have.
Now you see I have defined a variable for P..
I have put a PWT for L is just simply LS w As for who Majdi for date and C for Cal 2018.
So these are the variables.
The variables are the first digits P WDC and the commands that that variable that commands that inside
of those variables I would say are the ones on the right hand side.
So this is how we're going to create a new script by having those variables defined at the beginning.
So I'm going to log in to my machine.
I believe I already have logged in.
So what I'm going to do just for just for fun just for exercise or just for practice I'm going to go
one step back and I'm going to create a new directory called KADIDIA are and I'm going to call it my
scripts so it's just to tell you how you can differentiate from one directory to another anyway which
ever do to you.
Heck make sure there are specific directory for every script.
Don't just put it in your home directory or anywhere else.
This is not a good practice.
So I have this directory created in my script and I am going to create a new script when I call.
Let's say
var.
test.
And the first thing you have to do is bin bash and then you have to define the comments or the description
that it was created.
All this stuff I'm not going to take a lot of your time to go into defining every single one of it.
So I'm just going to from now on I'm just going to define the shell which is the mandatory thing.
So and then I go straight to running the script writing the actual script.
So anyway because I do know that time is valuable for everybody but I am very hopeful that you guys
do follow the standard that I have.
So first thing that is going to do is come put a comment here said define variables.
And those variables are first one is P equal PWT second one L. and LS W is for.
Who am I.
But you know what Actually there is a command called W and then x.
So I'm just going to put
who might just WIBC.
So that would be who my date for D and C.
Now since the C is a calendar and then I want the 2018 calendar so it has a space in the middle so I
have to put that in quote single quote should work.
If it doesn't work in your environment you could put double quote.
That's fine.
OK so now your variable defines.
Now what do you do is you could just simply say Echo
run variables tasks to start again.
Now I'm going to run the command.
Sorry I'm going to run the variable P to define the variable to run it or to get executed.
You have to start with dollar piece of.
This way the operating system or the other shell would know that you want to run that variable.
Okay perfect.
Next variable I want to run as l 31 as W II for one day and 51 C.
So it's just that simple save it.
OK.
Now let's give it a proper missions.
Seeds.
Yes.
That's very far one more time.
If you see the reason I came in to see if it has all the variables in.
OK.
Looks good to me.
But let's try to run because to test a script always run it.
Workbook and test.
OK.
So we do have some kind of error messages.
Perfect That is fine because as we learned we wanted to see where those messages are and how can we
troubleshoot and as you see the first message that it's giving us that there is in line 8 says unexpected
end of file while looking for matching coat or single course.
Let's go line 8.
It will go to line 8.
It's just like 8 and it's it.
See what I have and I put a single code here and I put double quarter here.
OK.
So one problem is fixed.
Let's run it again.
OK.
I think it ran fine this time.
Hopefully yes.
OK.
Run variable tests and those variable is PWT.
Is this the file is variable inside of the directory as Yuzu which is a variable date and a calendar.
So that's how it was coming up.
And you notice when I ran the command earlier test variable and it had a problem it gave me error messages
on two lines.
Do you know why.
Because first line is 8 which had that double code on one side and single called one side so that we
know that was it error but why we were getting the error on line 17.
Think of it let's check why we were.
I know but I want to show you exactly why.
So let's go to the file.
And now this time type 17
you know why I'm sure.
Now you know why.
Because in line 8 the defined variable was this which had a problem and in line 17 when it came down
to run that variable it says hey I can't run the variable so that's why it gave us error messages in
two lines.
OK.
So anyway that's how you define variables.
Going forward I will be using scripts rewriting scripts in different directories.
I could be writing in my my script I could be writing in just a script directory.
But anyway you could just follow just one directory if you want to or you could just do different directory
depending on how you want to structure your scripting skills in how you want to organize them.