 This video is part of a series. Be sure to check out the description of this video for the full playlist. And in the previous videos, we've been looking a little bit at some GUI options. We were looking at Zeniti, and we also looked at Dialog. Dialog is a nice GUI-like interface, but it's all text-based. But it's an external tool. It's not necessarily on your system. It's not a lot of systems available for most systems, but not always there. So can we make some sort of file selector purely out of scripts that should run on any system that has your shell installed? Let's go ahead and give that a try. I'm in a folder here, and if I list it out, you can see I've got five files here. And I'm going to create a shell script. I'll call it FileMenu. And I'm using Vim as my text editor, but use whatever text editor you prefer. I'm going to give it the shebang line saying that this is a bash script. And I'm going to say, Echo, please select a file. Now I'm going to throw an array into a, or I'm going to create an array from the file. So what I'm going to do is I'm going to say options, equal, and then inside parentheses, I'm going to say dollar sign parentheses, find dash max depth, one dash print, zero. And I'm going to pipe that into x args and do a dash zero. So basically this is just saying, you know, basically find all the files in the current directory. Max depth means only go through this one directory, don't go into subdirectories. We're going to say to print that information out and pipe it into x args, basically creating an array of all our files in the current directory. Now we're going to do a select option. So I'm going to say, or select function is a select. And we'll say OPT for options in, and we're going to pass it our array that we just created. So dollar sign and squiggly braces or curly braces, wherever you want to call them. Options and we're going to say the at symbol there. And then we are going to give it a final option of quit. So basically it's going to list all our files, give them each a number and make the last option quit in case you decide you want to exit. Now I'm going to say do and done. And let me go ahead and exit out. So we get some color coding here should have done that originally. So make it a little easier to read there. Now we're going to do an if statement. And we're going to say if inside double parentheses, we're going to say, reply equals one plus dollar sign, curly braces, pound options at symbol, then exit. So what this is saying here is we're looking at our array called options and we're getting the number of them. So if there's five files, this equals five. If there's 10, then it's 10. And then here we're saying add one to that. So basically we're giving each file a number and here we're saying if the user enters a number higher than the value of files, then we're going to exit. That would be the quit option right there. Then we're going to say L if. So if they pick anything other than that last option, which is the exit option, we're going to say reply is greater than zero and reply is less than or equal to dollar sign braces pound option options at symbol. And then we'll close our double braces here. Then we will echo your file is and we'll say dollar sign OPT. And then we will break out of this little select function. Close our if statement and we've already closed our select options. So let's explain, oh, you know what, no, let's put an else here as well. I'm going to say else echo not a valid option. Please try again, okay, I'll explain this and then we'll look at it. So first we're echoing out a message, then we're creating an array, which is the list of all our files in the current directory folders and files. So we're going to say, okay, we're going to give the user, we're going to use select so the user can select and whatever they select is going to go into a variable called OPT and the different options are our list of files or quit. Here we're going to say if the user inputs a number that is equal to the last option. So all our files plus one, it's going to then exit. Well, if we're going to check the reply, as long as it's greater than zero and the reply is less than the number of options, then we're going to output that they selected with the file that they selected and then break out of this little loop. And if they pick something that is not an option at all, we're going to say it's not about option. Please try again. Let's go ahead and save that make it executable using change mod plus X file and our file name. And now we can say dot slash saying that we're running a script in the current directory and the name of our script and when we hit enter, it says please select a file and it gives us options here and we can select now the number that we want to select. So what I'm going to say here is let's say I want this file. That's file five. I can say five and hit enter and it says the file is and the name of the file. If I was to run the same thing and hit eight, it would quit. And if I was to type in 32 or 23, it's going to say not about option and ask me to enter again. If I type in blah, blah, blah. I'm going to say the same thing until I pick a valid option, which is one through eight. I'll pick eight to quit. So that's that's it. We're going to do one little tweak here. You notice that we have dot slash. You may not want that. You probably don't want that in a lot of cases when you're working with your script. So let's go back in to our script here and let's change it so that here we can say that OPT, our option equals, and then we can say either dollar sign and parentheses or back ticks either or in this case, it's not a big deal in this particular case either way. We'll say base name of dollar sign OPT. That's saying just get the file name of that option, which should remove that dot slash. So now we can see all our options. If I pick let's say three, which is file five TXT, you can see that we have removed that dot slash from the beginning of the file name. I hope you found this useful. I'll try to remember put a link in the description to this short and simple script and in our next video we're going to add a little bit to it. So I thank you for watching. If you found this video useful and you find a lot of my videos useful, you may want to become a supporter over at patreon.com forward slash mail X 1000. There should be a link in the description to that page and there you can become a supporter with as little as a dollar a month. It would be greatly appreciated. If you can't afford a dollar a month or more, you can think about supporting by liking sharing subscribing and commenting. That really does help me out a lot. I thank you for watching. Please visit filmsbychrist.com. That's Chris of the K. There should be a link in the description. And as always, I hope that you have a great day.