OK so let's write some script where we can break this file system does operate this create a file called
file test that age and that as you deal with siobhán bin bash.
So what is wanted in this script for a provided file print summary
of vote permissions user has granted
but best be to do some examples to be sure that you fully understand what is wanted.
So we roll around the script to read one argument some file name or a file path.
And as a result we got.
If that file is for us readable right to go our executor will
so we receive some eco C'mon some message which is which says if the file is readable ridable or actable.
Now we can start with.
I will check because we want only one and one 5.
So if number of our demands is not equal to 1
we can bring in
provide exactly one I will land and you can also exit here with startles one.
Now you can also assign a variable.
So in variable called File we are assigning a value of argument one.
First I will add some command or so here variable assignment.
Now we can check if dead file the first and only one argument is an existing file.
So right in square brackets
an operator and then file file variable.
If that file exists we should do right.
If you can read override or exec a file for death I will create new variables which will keep value
yes or no.
So some command here.
Default variables and I will start the read variable.
So Vita read
equals two values.
No.
Right right equals two value.
No.
And exec equals to.
No.
All of them will have a value.
No.
And that is not true.
We will change it later.
Now we can check if file is readable.
So if break bracket and use our operator for checking if the file is readable
if a file is readable we can change the value of a variable to read to S..
That means that the file is readable.
Now we will check if file is right to go and for that we will use w operator.
So check if he's right to go if and in square bracket we are using W operator
and if that file is a right to go we need to change the value of variable.
Write to us
and check is if that file is executable.
So check if file is.
So for doing this check we will use operator X and of course if you need to assign value yes to variable
via exec.
Now we have or they don't need it.
So we can print to user some summary some summary so you can Bryde eco
but maybe Firstly I write some command here write somebody to user
and on the first go here we will write
read.
And here we are putting the value of a variable.
What I did.
So it may be yes or no on the next line we will print value of variable.
Var right.
And on the next line we will print a value of variable var.
So X exec to double Vajra and
and maybe we can do also some fancy either for that
so we can use another e-com
file and we can based out both of the file variable
but that's not all.
We finished only the part for the case that file exist.
If file doesn't exist.
We can print something as vote file variable does not exist.
So right you go to sign the file does not exist.
Now we are done.
So you can save descript
ground with permission
and we can meet but firstly create some test file using Dutch.
Dutch Hello.
Dot text and also create some testing directories so M-K dear
directory.
Now we see that we have one script one file and one directory.
So now around the script firstly without an audible one works fine.
Now we can use Hello text as an argument and we can see that we have read and write permissions.
Great.
So now we just grand exit could permission to that file Hello dot text and run the script again.
Great.
It works.
We can see that we have also exit permissions.
Now we can try to provide file with Hobart for example been beshe great.
It also works.
But what would happen if we specify our directory
we see message that dedicatory doesn't exist which is correct such a file really doesn't exist.
Same would be definitely for directory for example been
so ran script again vate directory called Ben
Oh no not been very sorry.
It's been only been you see that been doesn't exist but I don't like that behavior.
It would be much better to print to or that the argument provided is a directory Dubin is a directory.
So open our script again and we can change their behavior for a case when file does not exist.
But it is directory instead.
So open file
and under our state command
we'll do some new if statement and we'll ask if we do
file if the of file variable is not a directory and if it is a dedicatory we will print that value of
an argument is a directory.
Otherwise we will write that file does not exist.
So we can also prebend before the value of variable file file.
So file and devolve or variable file does not exits.
And now we can save the script and we can try to run it again at agreement.
It's like a big and we see now that slash and burn is directory.
Great.
So now we have break this file.
Test operators and I can mention that they are usually used.
And it is good to know them especially they are used for some backup scripts where we can for example
check if destination for that exists and if not we can create it as backup is sometimes done to timestep
folders.
You can imagine a situation in a company which does daily backup and for current day it is already some
backup done.
So it can be time consuming to do because again if it is already done by checking if times then for
the exits and it has some file in it's v. Vaughn do any more useless copying of files.
So thanks for watching and see your next lecture.