All right.
So let's create the script.
I'm calling it lab23.
And what do we need?
Well, we need to start with the shebang.
And then we need to provide the directory where it should
look for the files as an argument.
So we need a $1.
And that means that if you don't have $1,
the script should be stopped.
So I can do that by using a test.
So test minus $1, exit 9.
There is no question that any specific error message
should be provided.
So this should be doing it.
Then we need to remove all txt files in the directory
to txt.back.
Well, that is, in fact, pretty easy to do for in $1
slash star dot txt.
And first, again, I want to verify that this is working.
So do echo $idone.
OK, this is the role body of the script that I want to use.
Let me make it executable.
And now let me create a directory files
and create files file 1 dot dot 9.
That's a range of file dot txt.
And now I'm going to run the script on this files directory.
And we can test two things.
First thing, echo $?
Yeah, it did return the access code 9.
So that part is successful.
And now lab 23 files.
And there we can see that it is showing
the names of all of these files.
So that is OK.
And it means that we are almost there already.
And based on that, we can get back to the script.
Instead of echo $i, I am making that move $i,
because that is what we wanted, right?
Oh, no, not move.
It's a copy.
So copy $i.
So we copy $i.
So we copy $i to the tmp directory.
That is what it wanted.
Is that right?
No, that is not right.
And we have two problems here.
Problem number one is that I have this $i
as a relative file name.
It includes the directory name.
I don't want the directory name to be included.
So we are going to do it a little bit different.
I want to change into the directory
before we are going to work on the script.
And that makes it I have just the file name
without the subdirectory, because the subdirectory makes
it difficult to move $i to tmp, because then I
would have tmp file name.
I don't want it.
So I'm going to use cd $1.
And then I want to do another test.
Before I'm going to copy it, I am going to do a ls minus l,
because it's funny, on $i.
Running it again.
And there we are getting a ls cannot access files slash
dot txt.
Of course, that makes sense, because I cd'd into $1.
And now I'm using $i in $1 slash.
That's not going to work.
From this loop, the $i needs to be simplified.
Now it should be working.
As you can see, the files are now listed as separate entities.
And that makes it so much easier.
So now I can use cp.
cp not ls minus whatever, but cp $i to tmp.
And we call it $i dot back.
And then we run it again.
And now when we use ls minus l on tmp slash star back,
we can see that the mission was accomplished.
So this is what I had in mind as the solution for this lab.