 This video is part of a series. Be sure to check out the description of this video for a link to the full playlist. And today we're building on, again, we've been working with functions in our shell. So let's go ahead and go to the function script that we've already created. And here we've passed some variables to it, but let's talk about global and local variables. If you've done anti-programming before and you've used functions, you are probably very familiar what global variables are and what local variables are. And if not, we're gonna go over it today in shell scripts. So basically a global variable is a variable that you set and anywhere in your program, you call that variable, it is going to use it unless that function has a local variable and a local variable is set to a certain function. It does not leave that function. So what we're gonna do here is we're gonna create a variable and we will call it x and we'll just say x equals 20, okay? So anywhere we use dollar sign 20, or sorry, dollar sign x, we should get the number of 20. So let's go ahead. I'm gonna delete this line, this line, and I'm gonna change this line to be an echo command. So we're not calling our function at all at this point, but I'm gonna say global x is dollar sign x. So when we run this, which is script is or even aid executable using change mob, we did that in a previous video, forward slash meaning current folder, run this script, you can see x is 20. Now, let's go ahead and go into our function here. And here I'm going to say global x is still dollar sign x. And here I'm going to call my function. So what's happening here is we're saying, okay, x equals 20, echo this line out with the value of x, then call this function, which is going to display this. So let's go ahead, save that and run it and it works just as we would think. So even inside our function currently x equals 20 and I can change that, I can come up here and change it to 10, run the script, you can see now both say 10. Now, let's say we want to have x inside our function that is a different x than the global x. Well, we can do that by saying x equals 20 at this point, let's say, but we're gonna say before that local, meaning now we are changing x or saying the value of x, but only inside this function. So now I can say echo local x is dollar sign x. So if I run this, now we get our global x is 10, global x is still 10, but local x, so anywhere in this function from this point on, x is now 20, but that doesn't change our global variable. So if we go back into our script here, I can now say echo global x is still dollar sign x. I run this now and we can see global x is 20, global x inside our function is still 20, then we changed x inside our function to be, I'm sorry, I said 10, I said 20, it's 10, local x. So anywhere inside that function from that point on x equals 20, but then we move outside that function back out into our main portion of our script and x is still 10 outside of that function. So that is global and local variables in bash in your Linux shell. I hope you enjoyed this video, I hope you found it useful. If you did find it useful, think about becoming a supporter over at Patreon.com, forward slash metal x 1000, even a dollar a month is very useful, a very appreciated, if you can't support financially, think about becoming a supporter by commenting below, liking and sharing this video and also subscribing to my channel. I thank you for watching and I hope that you have a great day.