Hello world yes this is the basic script that most of the time that I've seen people write whenever
they start learning scripting languages so we are learning bash scripting languages and a script that
we will write as to echo or to output on the screen that reads Hello world.
I remember when I was in college the first group that was given to me by my teacher and or my professor
was to write a script that will output or print on the screen that would read Hello world.
So anyway I am going to do the same thing for you guys that I want you to create the first group if
you know this how to create a script.
Awesome.
But start with me.
Let's go with me so we're going to start with creating a first group that will output Hello world.
So I have already my next machine session opened and I am logged in as myself now as a practice as I
mentioned before that always create your script in a specific directory so it will be easier for you
to remember where those scripts are.
So let's do C.D script or have already created it you should have that too if you follow my earlier
lessons.
If not then go ahead.
Run the command make D-I are followed by the script and it will create a script directory and script
if you do ls Mannus else you probably not going to have anything.
If you've never had a script before here.
If you do then go ahead and delete the script the first script delete is Hello world.
It's just permission denied.
Why is that.
It is owned by me.
It is owned by my group and I could remove word by looking at this.
W It has.
Right.
Right permissions.
Why can I delete it.
That's a good Tobler shouldn't say that.
Well right I know why I can delete it because when I created the folder or directory called script I
was root.
So let's go one step back C.D dot dot to LS minus L and you will see.
Yeah right.
See right here says this directory is created by root.
So anything under this directory will be protected by user root.
Nobody could touch it.
Or deleted.
So the best thing I should do is to become root
go into my home directory and I will simply remove that directory now.
So this will start fresh.
OK so now it's gone.
That's exit out of that route.
Make sure you are yourself.
Yes.
Are you logged in self.
Also you could check by looking at the prompt that tells you the name of the user logged in and the
server name.
So now we are in our home directory and now we are going to create a directory called scripts and we
will put all our script from this point on to our folder called script.
Now make sure it is there.
Yes it's there it's the end and now it is owned by me.
Now you don't have to run all the scripts as root.
The only time you would have to run scripts as root if the command is that you are adding inside your
script required root privileges.
Yes so you can run any any command like P.W. DNS or anything that do not require root permissions.
If you are running other commands let's say DMI decode O.D. message or DPF disk command those are the
type of commands that require root writes.
So it's better that you run those commands.
Those scripts you create those scripts as root anyway.
So let's get into our Scripsit tree and now you see we don't have any file or any directory in our scripts
directory so we will create our first script and we'll call it hello world.
And you could put that bash as well but since we will be working primarily with bash shell so you don't
have to specify the extension so just simply hit enter once you are in the VI mode.
You specify the shell so we want to run the script as Bash.
Good second thing.
Who is the author of The Script.
Will say it's myself perfect.
Then again a comment.
Date script is created.
Pick any date.
So let's say if you're picking 0 8 slash 20 slash 20 20 ok then put in a little description description
and I'll read this script will output
Hello world
on the screen.
That's it simply that.
Now if there are any modification so you could put a date modified and then you could put the date since
we're doing the first time we could just put the same date as you put a date create it.
OK.
So our show is defined our comment is defined.
Do we have to add anything.
No it's just a simple script.
So I will go ahead and write the script that will print echo Hello world and that's it.
Now you could just to escape bottle fed and write quit and your script is created.
Now varified Yes the script is there but you can not run it.
Why.
Because it does not have executable permission right here.
So in order to assign proper executable permission you will have to run the command change maade all
plus executable.
Hello world.
And by the way I'm using tap that auto completes the file and if the file does not exist will not autocomplete
as an example let's say a fine set of h e l o put a L L and hit TAB c it's now going to work.
So it has to have a correct spelling.
OK so we have modified the permissions.
Let's verify it.
Yes.
Now it has the executable permission as if you see as soon as we could give it gave it permission its
color change as well.
Now please remember don't focus on the color.
As I said earlier as well that some time maybe you probably creating a script in Solaris or an X or
in any other Unix or links player.
That does not give you that color changing scheme or that depends on the environment the shop.
So that's why just focus on that it is executable by looking at executable permission.
OK now perfect.
Now let's run it.
So again you can run it through the whole path.
Vetches absolute path
script directory and hello world and hit enter and then go your full script is created.
Isn't that fun.
You have just created your first script which outputs on the screen.
Hello world.
Now what I'm going to do is I'm going to run the script as a relative paths a dot slash Hello world.
There you go.
It does the same thing but it executes it with a relative path.
Now if you notice there are no lines in between on top and bottom so I wanted to make it more clear
more neat look.
So what I will do is modify the script hello world hit enter and now I'm going to put one at O'Hare
and one go here.
So when I put these echoes inside then it will actually generate an empty lines before hello world after
hello world and date modified again.
I could just put it like let's say if you are modifying it a day after the first time you created then
you just put 21 save the script.
And now let's run it.
Hello world.
Nice.
You see now it is giving the output that you want.
Now as an exercise I recommend you to go ahead and create a couple of scripts like that that will output
on the screen like my name is Emraan absol.
I love to teach you and I and whatever that you want to add just I'll put on it chopped the lines whichever
way you want it.
This will give you some practice on how to create simple script.