Script format having a prop or a format inside of a script is very important.
Why is that.
Because I'm going to say I'm going to bring back the same analogy.
You create a script.
It's a very long script and a few months passed by and now you need to modify the script or troubleshoot
something in the script you have.
Sorry you have written down the script but it's all over the place.
The variables up your comments are nowhere to be found.
The description is no where the commands are left and right.
There's no indention nothing.
So there should be a proper format that should be follow so that someone can come in and take a look
at your script and says Wow that's a great job.
Whoever did that so easy to read and so easy to understand.
And what are those format.
One is first and foremost is define show.
This is something that you have to define.
You could say it as a part of format are mandatory.
You have to do that you have to define a shell then you create a first script.
You have to let your operating system know run that script as bash script if you're doing a corn Chell
you have to specify poun hash slash Ben slash corn shell.
Anyway when we write our first script we'll cover that as well.
Then comments right after defining the shell you have to put the comments and those comments.
Always starts with pound sign.
And the reason I am telling you that you should include comments is because comments should tell what
your script does when your script was written who was written by.
Was it there any mortification anything that you wanted to include that a user or someone else reading
your script can understand what the script is about.
Please add that to your comments then define variables variables what those variables are.
Real code that.
Not to worry about it but just to let you know quickly the variables is just like an alias.
If you have a long command or if you have a bunch of e-mails what people do is they give it a letter
equals to a whole big command becomes their variable.
So define your variable at the top of the comments.
Then you run the commands whatever the commands that you want your script to execute.
You need to specify those commands.
Or if you do not have commands or if you have any statement scripts that's where you put your Sekhmet
scripts those statements scripts are if then while for loop or so on.
Now when you have statements defined you should start if the line where you're going to put an F hit
tab because this way it will show that your if statement is starting from this point on.
There is nothing that that script will translate your tab into something else.
You can use spaces you could use tabs anything that you want but try to make your script formatted in
a way that if someone or when you read it after a year or two year you'll say oh this is what I did
it's so easy to read.
So let me log into my Linux machine again and I'll tell you exactly how you should format your script.
Ok it does in my Linux machine I'm already in my directory purrfect.
I created a script earlier.
Or a file earlier call a paci script.
I'm going to take that same script and we'll formatted the way I had just discussed it.
So to do that I have to now do a vi on that script and I am sure you guys know how to use vi some some
of you are familiar with vim is probably a hash word you know vi I like to use vi it's kind of old school
but the good thing is that it's available and pretty much all the Unix or Linux flavors so I could never
learn something new and not utilize it.
All the words.
Because I use vi in many system like Solera Sai X systems and sometimes of them is not available.
So VI is something that you will find anywhere whichever's the system you logging.
So anyway I'm going to use vi to edit this file which will eventually become a script.
So you hit enter.
Now the first thing as I said you have to define a variable which had been bash.
If you look at the back you'll see the first thing is defining your shell.
I want to run this script as a bash script.
Perfect.
Now the next thing I said to add a comment OK.
Always add a comment as I usually add a comment is like purpose
testing script format date put any date let's say August 20 2040
modification.
If you have done any modification to the script put down the date of the modification so 0 2 0 8.
So last modification of course since you're reading this first I'll put 20 again.
OK then anything that you want to add please go ahead do so.
So if I had just put in LA LA LA or whatever it's just a comment.
It has no effect on your script.
OK.
Perfect.
I understand Imraan But how come the first line that you have is slash been slash Bash has a comment
in front of it isn't that isn't it will be considered as a comment as well.
Awesome question.
Trust me I had the same question but let me tell you this is just how it is sometimes you know it is
how it is.
So Linux will understand this as actually a shell script.
And it always starts with pounde and hash.
Why.
I honestly don't know if you really want to know why.
You could ask someone else who really know inside out when they came up with writing scripts.
Or you could I'm sure go online and find out why you have to define the hash anyway.
Put that in the back of a head.
You have to remember this no matter what.
OK.
So moving on then you would define.
Next thing is a variable variable is something like.
I want every time I want to echo something I just want to say a and that echo so let's say in case I
want to have single code Imraan or you know what I'll say my name is Imraan
this is how you define your verbal and then you could just do at Go dollar a.
Then it is going when you say a dollar a.
By the way this is just the scripting language I already started teaching you.
But that's OK.
You need to understand the format so variable I have defined here that every time this command will
run it is going to call upon this variable.
So why didn't I put that whole thing here.
I can of course but what if you are working in environment that requires a huge line and does a huge
things then you it's better that you put those variables in there.
Then of course then you put command.
Let's say you want her on a date you want her on a command of minus age or so on.
Then the last one I included statements if you are including statements in your script please do not
start from F..
Let's say dollar a.
Equal.
That's a file or whatever.
Do not start like that.
Always put tab like this.
So if something is equal to that file and then tab again then echo this
else and call that and then fee to close the statement you'll see how it is that if Kintyre if statement
came to be on the right hand side.
So you know that this is the statements that I want to run and they are in did to the right side.
What are those statements.
I never seen that.
Don't worry bout it.
I'm going to cover that in my next lessons.
The purpose of this lesson is just that you know that why would I follow this format on the following
lessons.
That's why I wanted to code that right now so you wouldn't know.
This is the best way to put your scripts together and it would be so easy to remember when you come
back to.