Instructor: Shell scripting.
Let's get into some fun.
Yes, everyone, it's time to get into some fun,
where we're gonna create our own scripts,
our own commands to run and automate tasks.
So what is a shell script?
So basically a shell script is an executable file
containing multiple shell commands
that are executed sequentially.
And every time you create a shell
and you have a first command followed by a second, a third
and fourth, always the first command will be executed,
followed by the second and third and so on.
So the first line of a shell script file contains
the definition of the shell.
The first line is the shell itself.
Always define the shell with pound, bang,
slash, bin, slash, bash.
In Linux, the most of the time,
the exclamation point is referred to as a bang.
So the first line of a shell scripts always start
with the shell is gonna run in.
Most of the scripts that we will cover are all gonna be
in bash scripting.
All right, then inside of a shell script,
we also have comments, where we could tell
what this command or what this script does.
Every time we put comments, we always start with a hash
or pound sign, followed by all the comments
that we want to add.
Then we have commands, of course, what exactly you want
to script or want the script to do.
And then we have the statements, which will tell
the script if, then, while or do or for loop,
all those conditions that we will cover, one by one.
And those are different shell scripting.
A shell script should have executable permissions as well.
What it means that when you create a script,
of course a script is just an empty file.
Everything in Linux is just a file, a flat file,
until you change it to an executable or link
or just a flat file.
So if you go back to the executable permission learning
that you had, you remember
that the third bit in a file is always executable,
which is X, right?
For the group and others,
the executable permissions is represented by X.
So in order for a script to run, it has to have X bid on it.
A shell script has to be called from absolute path as well.
It always has to be, you always have
to define the complete path of the shell,
meaning in this case like, like home, your user directory
and the name of the script.
If it is not an absolute path, you could still run it.
If you are in the current location, then you will have
to do is put a dot, slash
and then the name of the script.