[Intro Music]
I have just demonstrated to you how
you could change your permissions
for a specific file. You are able
to assign specific permissions, to
add permissions, or to remove
permissions. And for that, you need
to use command 'chmod'. Please
know that if you want to modify
permissions for entire directory,
you need to use additional option
'-R'. Great. Now, let's
create a sample script, and make
the script executable script. And
actually, we will create simply
file, and you are not able to
execute any file in the new system.
You need to make this file
executable first. And let's try to
do this here in this lecture. Let's
clear terminal, and here let me type
the following command, 'touch
script.sh'. Notice that I have just
added the extension 'sh', that stands
for Shell. And the reason for that
is that I am going now to create
executable script, and this script
will be executed by a specific
process. And that process will be
bash shell. And that's why if
you're going to create executable
scripts that will be executed in
Shell, you should add extension 'sh'.
Of course, you could go on
without any extension; and in such
way you will be able to execute the
file as well. But it's a good
practice to add extension. All
right, let's create a new file
'script.sh'. Let's list files and
folders here. Let me actually
remove 'new-file.txt'. I don't
need it anymore. And now I see
script.sh file here. And notice
permissions for this file. It is
readable, writeable, but not
executable by owner; readable,
writeable, and not executable by any
other users in the same group
'bogdan'; and only readable by
all remaining users in all other
groups. Could you quickly tell me
decimal representation of those permissions?
[Clock Ticking]
This section stands
for 4+2, 6; this 4
+2, also 6; and here it will be
4. So, resulting permission is
664. Great. Now let's make this
file executable. And I want to make
it executable only by owner, this
user, 'bogdan'. And I will modify
only this section. And for that I
could use either decimal
representation of the resulting
permission, or I could add only
execution permission for user. And
for that I'll use 'chmod' command.
And here I'll type 'u', stands for
user; next '+', I'm adding
permission; and here will be
execution permission 'x'; and here
will be name of the file, 'script.sh'.
Let's run it, and let's verify
permissions now. And you'll see
that now this file script.sh is
marked in green color. And now it is
executable by user - read, write and
execute, 'rwx'. And now let's open this
file, 'sh' file in Nano Editor; and
let's add some shell commands there.
'nano script.sh'. And first what you
need to do here in this file is to
add reference to a specific
executable file that will run this
file, this script. And I'm going to
run this script using bash shell
process. And for that you need to
use following line. '#', next
'!', and here will be
path to corresponding executable
that is supposed to run this shell
script, and path is following '/bin
/bash'. Actually, you could
find the full path to bash shell if
you type 'which bash' in terminal.
Actually, let me quickly do that.
Let's exit without saving. And here
type 'which bash', and here in the
system I see that bash executable
file is located in '/usr/bin/bash'.
But let me actually have a look at
contents of the 'bin' folder, 'ls
-l'; and you'll see that this
folder is actually linked to '/usr/
bin'. We have talked about links
before. And that means that I'm
able to use either this path as
reference to the location of the
bash script, or simply '/bin/bash'
because if I enter '/bin/bash', it
will point to 'usr/bin/bash'. All
right, it sounds a bit complicated,
but in fact it is very simple.
Let's go back to editing of the
file, 'nano script.sh'. And here I'll
type same line, '!
/bin/bash' like so. And
it tells system that this
executable file 'bash' will be used
for execution of the script. Great. And here
let's simply type 'echo', and here in
double quotes, "Hello from the
custom script", like so. Let's now
save contents of this file, like
so. Yes, Enter. And now let's try
to execute this file. And if you
want to execute a specific script,
you need to enter simply absolute
or relative path to this script. In
this case, this script is located
here in home directory for this
user. It is actually current folder
represented by '.' or by '~' sign. It
is home directory for this user, or
absolute path is '/home/
bogdan/script.sh'. And
actually, you are able to use any
of those variants. Any will work.
Let's go try to use this
absolute path, and simply press
Enter. And I see, 'Hello from the
custom script'. And that means that
bash shell has executed this
script.sh file. You don't need to
enter any arguments or options or
any other commands, simply path to
corresponding executable script.
That's it. Now let's try to use
relative path and simply type
'./script.sh', and I see same
result, 'Hello from the custom
script'. Let's try to use reference
to home directory, '~/
script.sh'. And I see same result
again. But if I enter simply
script.sh, I'll get 'command not
found'. And now question to you, why
I get this error when I entered
this command without full path to
it? Answer is very simple. At the
beginning of this course, I have
explained to you what is the PATH
variable, and how actually Linux
shell understands that you want to
enter a specific command. And if I
enter 'echo $PATH', I will
see a set of different paths that
are concatenated using a colon.
For example, here is location of
some executable files, '/usr/local/sbin',
next one, next one, and so on.
And now this script.sh is located
simply in '/home/bodgan'.
And this path is not in this list,
that's why shell is not able to
recognize that I want to run some
script named script.sh. If you want
to be able to run some scripts in
such way without full path, you
need to add the folder name where
the script is located to your PATH.
Simply concatenate to existing
PATH. But it's not a good practice
to add home directory to PATH. It's
a good practice to create 'bin'
folder in home directory for your
user and place all executable
scripts there. But let's talk about
it in the next lecture. I will show
you how to do that, and how to
modify path, and next after this
action you will be able to execute
script like this anywhere in any
folder. I will see you in the next
lecture guys. Bye-Bye.
[no audio]