 OK, today we're going to be looking at getting user input, but not just one character or a string or even a line. We're going to get multi-lines of text from a user. There's multiple ways you could do this, but a lot of them require using cat or something like that. And then when the user's done typing, they have to hit Control-D, which is inconvenient for people who aren't used to shell environments. You just want to be able to enter something. And what we're going to do today is basically, when they're done, they just hit Enter twice. So whenever there's a blank line that they enter, then it's done capturing the input, putting it into a variable, and then we can do something with it. So let's go ahead and create our script. I'm going to use Vim as my text editor, but you use whatever you want. And I'll just call this input.sh. OK, we're going to start off with a shebang line. So bin bash, because this is a bash script. Also, this code will be up at Pastebin. The URL for that will be this right here. I'll put that in the link in the description of this video. So let's go ahead and get started with our script. I'm going to create a function. That way we can call this more than once within a script. So we're going to say function get input. And then after that, we're going to type in echo. Actually, I should put that in the function. Let's go ahead and say get input. So we've created an empty function here, and we're calling it. And in here, we're going to say echo please enter some text. Now, you may want to tell them when they're done, press Enter twice, something like that. You can put that in the message. But what we need to do is we're going to create a variable. And then each time they hit Enter, we're going to add that line to the variable. But since we're doing this in a function and we might want to do it more than once in our script, we want to make sure we clear out that function or that variable. So we're going to use this unset. Unset is going to create the variable empty if it doesn't exist. But if it already exists, it's just going to clear it out. And we're going to call our variable user input. Now, we're going to do a while loop. While, read, line, do, and done. OK, so we're going to loop through what the user is typing. And we're going to use our user input variable. And we're going to use this plus equals. So we're going to plus equals. We're going to say dollar sign line and give it a new line each time they do that. Otherwise, the text they give us, even if they hit Enter, it would put it all on one line. We're saying here. So basically, as they type, every time they hit Enter, that's a new line. We're going to put in a new line variable. And then we're going to append that to our user input and add a new line character to the end of that. And then we're going to say, we're going to check the variable line. And we're going to say, if that is empty, then break out of this loop. And then when we're done, we can put this in our function or out of our function, depending on our script. But we can say, echo you entered. Oops, I didn't mean to hit Enter there. You entered. And then we'll say this and we'll say echo dash E because there's multiple lines. If we don't do dash dash E, it's going to show it all on one line. But here it's going to look at these new line characters as new lines. And we're going to say dollar sign user input. If we've done everything properly and we make our script executable, we can then run our script. And it's going to say, enter some text. And I can say, hello, world. I can hit Enter. This is a test. Enter. And this is more. And if we're done, we hit Enter again. And it prints out. You entered. And it enters our text along with the new line. Now the order of things in here may vary on your needs. Again, you may want to echo out what they inputted in each function. But I put it outside of the function here. Just depends on your case scenario. Also here, you can see that I have added the new line before I checked if it's blank. So do you want that empty line in the variable or not? Here, it's going to be in the variable if we were to take that and put it before that. There won't be the blank line, which is probably a better way to do it. But again, it all depends on what you're trying to accomplish. So if you need to get multi-lines of input from a user, I find this is the best way of all the options I looked at. There are options to where you can open up a text editor, Vim or Nano, and then have that all saved to a file. And then you can pull that and put it into a variable. But now you're using a text editor. You can set to use whatever their default text editor is, or you can set one. But then you have to rely on them, hit and save, and all that. You can use the cat command and dump what they're typing into a variable or a file, but they have to hit Control-D at the end. And so I just find that awkward. Here, it's just every time they type a line, it adds it to the variable. When you hit Enter again, if you didn't enter anything, it breaks out of the loop. And you have your variable with the user's input. Anyway, filmsbychris.com, that's Chris the K. There's a link in the description to my website. There you can find all my videos. You can find scripts and programs I've written. And you can also find a support section where you can support me at patreon.com forward slash middle x1000, or through PayPal, or LibrePay. You could be the first I've accepted LibrePay for a couple of years now, because people requested it. I don't think anybody's ever given me any money on LibrePay. You can be the first. If you can't support me that way, think about liking, sharing, subscribing. As always, I thank you for watching. And I hope that you have a great day.