OK moving on to the next lesson.
This lesson is also above for loop and it's extension of the last lesson they've encountered here.
Here we are going to Khowar again a couple of four scripts one scripts that we wanted to Khowar is how
we could rename files that has got to 64 extension to none.
Or any file that you want to change with a different name.
The second script will Khowar is checked to see if files exist.
Now the file exists sometimes you have to actually log into a different server and you need to find
out if in a different server a file exists on that so as well or not.
So you could create that script in there and you could check that both of these scripts have a very
very much application to the to the real real life.
Because I actually worked on many of these these types of task where I have to change or rename the
files or I have to check if those files exist or not.
So I'm going to code these again realize example log into my next machine straight here I am logged
in as myself and of course I am in my home directory and I'm going to create a new script and I'm going
to name it rename files and we're going to start with our same practice.
It only going to take a few seconds.
So please get into the habit of doing
day
description which is for me the most important one.
This script will rename files and ending with XTi.
And then I have to do the modified date which is since this is the new one.
I'll just put the new the same t.
OK.
Postscript The first go was going to do.
It's going to put create a variable for a December pick a different variable and like finally you can
put I again if you want to an asterisk text is going to look for all the flaws in the current directory
that has the ending name with T XTi and Estra because you know it's a wildcard it's going to look for
that and it's going to put in a container a name finally.
OK is going to do that.
What else you want to do.
Now I want to do move whatever comes from that container.
So whatever comes from the container name it rename it to file name percent's sign changed right here
to none and done.
So once again it's going to get the list of all the text file and put it in a container and the content
name is falling then it's going to do is move.
That list of all the files that are in that container and it's going to rename it to.
And this is the this is the string or syntax that you have to pick which is dollar curly braces finally
lame which is the name of our actual file.
And this percent sign is actually going to it's actually like a wild card text saying what a word that
is text.
Change it to none.
And then be done with the script
the proper Tsukuba permission.
Now let's run it.
And it's not the right one you ask and it says can not stat Astrakhan text.
No such file or directory perfect.
It means it works how it works.
Why did it give us error message.
Because we do not have any file in our current directory that ends with Dottie accesory.
If you do ls minus l astronautics t c Nothing is in there so we will create some files.
So touch Imraan to t XTi Afzal TXI T or any Dotti.
So we created these three files and these three files will be renamed to dot.
Done.
When I run the script.
So let's run the script rename falls after it ran and let's verify it.
And it did change from itx to not.
So that's one example you could change multiple files with just script in one shot.
Next one we have that you want to code is checked to see if file exist.
This one I use it.
I have used it in the past as well many times.
So let's do copy rename files and Allwine to to check files
copied saved us time.
So now we IDist files leave everything in there except descript will check for files.
Does that change the description.
Everything stays the same.
Andrew morph to script and start the new scripts now.
What are the files that you want to check so I won't.
To first create a variable in the variable just put files equal.
Put double coat slash at C pass word every system has that right slash at C group.
Every system should have that too.
If not then you have a problem right.
So that's all you want to make sure.
Shadow at c and and s switch.
Duck QOF at C Ss h d underscore S-sh underscore config.
And the last one.
I just want to put fake is just a fake.
I wanted to see if the script actually finds it.
Hey this file does not exist.
All right.
So either the file of close the coats.
These are all the files I'm putting in a variable called files.
Good variable is defined now where you want to put at Koso put an empty line.
For now you are creating another variable for a file
files.
So all these files that are in this variable.
Now I want you to put those files coming from this variable into another variable and that variable
called is just a file.
Lower case file do.
Now here's a new one.
If exclamation.
E.
File
this is going to do is if the files are coming here that do not exist.
Exclamation means do not equal to the files that I have specified.
Then echo the file.
Do not exist.
Echo another empty line fee.
And.
OK.
So basically what I'm saying is if you go and look for all these files right here in this container
and then put all these file in a new container and then do is test if these files actually exist in
this system.
And if they do not exist then tell me they do not exist if they exist don't worry about it don't tell
me.
So that's why I didn't else comment.
So let's run it and now check files OK.
You see right here it says at c S-sh d underscores SH config do not exist at c fake do not exist.
OK yes.
S-sh underscores decision config that file.
Actually there is a file there but I actually by mistake picked the wrong one.
Actually it is at C S H.
Actually I am not rude that's why it's not going.
No S-sh.
Fig.
Yes this is the actual file.
So but I haven't specified wrong here.
That's why it seems to not exist.
That's how this script is doing so what's.
Why do we need this group.
Because as I said before what was I said before.
Many times you do have to go into a different system to check if those files exist and make sure even
if it's application file or database file you need to verify those files exist.
And that's why you're not having the problem because files do not exist.
That's how you run the script.
You could specify different files to test on it and see how it works.