 and welcome today we're going to be looking at creating libraries with functions in them that we can import into our bash scripts. It could be useful. I don't use it too much because normally when I write shell scripts they're very short and I'll just throw the function in there. But let's say you have multiple scripts are going to be using the same functions. You don't want to repeat that code especially if you want to make a change to the function then you have to go and change in all the different scripts. So let's go ahead and just make a very basic script here. I'm going to use Vim as my text there. You can use whatever you want. I'll just call it main.sh and I'm just going to put in a little template here that I have. So we have our shebang line, a little copyright notice, and then our main function here. And as you can see it calls the main function at the bottom here which is going to echo welcome, sleep for a second, and then exit. Let's go ahead and exit out of that. Change mod plus x to make it executable and now we can run our script welcome and a second later it exits out of the script. Let's say you know in a previous video I showed you how to write a function that scrambles the words that are given to it. So let's go ahead and go back into here. Of course we can't just go like this. Let's say we want to say scramble welcome to my script. I'm just giving it a little bit more to scramble. But if we run that we're going to get an error because scramble is not a command and there's no function in the script called it and there's no executable on our system called that. Now one thing I can do is I can come in here and I could paste that function that we did in the last video which I actually added an actual echo here at the end so it puts a new line at the end. You may or may not want that depending on actually that might not be a great idea if you want to scramble a word and then put it in a sentence. Anyway for for this video it's fine. Now I can run that and you can see it's scrambled our sentence and each time we run it it scrambles it a little bit different. But let's say again you're going to use the scramble function in multiple scripts. You don't want to write it multiple times even if you're copying and pasting it because if you want one that's inefficient you're writing more code than you need to and if you want to make a change well now you have to go and change it in multiple scripts. So what we can do is put that in its own little script file and call it into this script. So let's go ahead and delete the function out of here. So and now again if we run it now without that we get that error that scrambles and exists but if I list out what's in this directory you can see I have a folder that I called libs for libraries and if we list what's in there I have a script called scramble. You can call the script where you want and you can have multiple functions in there right now. If I cat that out you'll see that it just has that function that scramble function. So what we can do let's go back into our main script and source that file. So at the top here I'm going to say source and I'm going to give it the name of that file scramble. So now and I like to put stuff in quotations it's not necessary most of the time but there we go. So now I'm saying source this file which basically just like if you're writing in C you can include header files which is basically taking that code and it's basically like that code is written in this file basically we're taking this script and it's being pasted into this file. So now I can save that I can run our main function and as you can see it scrambles our sentence let me clear the screen run that again anytime I run it scrambles it differently. So again you can have multiple functions in there that aren't called in that script but then you can call them in your script. So you can make your own library files this way and prevent the you know repeating of code which can get sloppy if you're working on a bigger project. Again that's something I use often because most of my projects are just one file but if you were to be writing a whole suite of scripts and you have functions that you use regularly you can put them in a file and source them into your other files it can definitely be useful on bigger projects. If you enjoy this video filmsbychrist.com that's Chris the K there's a link into the description to my website there you can search through all my videos from both my channels and you can also go to the sports section or check out the description of this video for patreon.com.com.com or you can support me through PayPal. I really appreciate it you also get early access to videos downloads of videos and if you can't be sure to like share subscribe comment I appreciate you watching and hope that you have a great day.