 Well, I've done tutorials on getting color in your shell scripts before, and it's not something I do often, because you gotta remember all these exit codes. So, for example, you know, if I say echo, I can say this is a test, and we get this is a test, but I can use these escape codes by adding the dash e argument to my echo command, and then within my string here, I can say backslash e for exit code, and then bracket for m, and what this will do will underline my text. So there you go, but now you also see that now everything I type is underlined, so we have to disable that after using it by adding in at the end of my string here, backslash e bracket zero m, and that puts everything back to default. So what we have here is say, okay, echo this out, look for exit codes. This is an exit code. This exit code is four m, which means underlined, so this will be underlined, and then this is another exit code, zero m, meaning back to normal defaults. So, it's kinda hard to remember all of that, probably even if you use it regularly, because you can, there's all these different colors, there's background colors, foreground colors, there's blue, light blue, green, light green, dark green, dark blue, reds, orange, you know, all this different stuff you can do. So lots of exit codes. Well, a while back, I saw this post on Reddit, and I thought that I would share this with you today. But basically, this guy has a great idea of taking all those exit codes and putting them into variables at the beginning of your script, or you could actually even throw them into your BashRC if you're using it on your regular system, but for coding, you can throw these as variables at the top of your script, and then utilize them within your script. So, he has a one-liner here that does a bunch of stuff, so I'm just gonna grab that one line. Oops, wrong keys. Let's try that again. Control C, move this out of the way. I will go back in here, and I'll create a new thing. I'll just call it tutorial.sh. And this is gonna be a BashScript. Well, before we do this, you're being like, let's actually just paste in that one line. So this is all one line. It's looping around here, but all one line. But each one of these semicolons, as you know, means a new command. So we want to, we can leave it like this in our code, but I like to break it down and make it a little bit easier to read, have each one on its own line. So what I'm gonna do is I've saved that. I can cat it out, as you can see here. And let's use sed to knock each one of those onto its own line. So I'm gonna say sed-i, meaning edit this file in place. And then we're gonna substitute some stuff in the file called tutorial. And what are we gonna substitute? We're gonna find each semicolon and make it a new line character. And actually, each one of these semicolons, I think has a space after it, so let's do a space two and see how that works out. So we did that and since we did a dash i, instead of seeing the output to the screen, it just edited the file where it was in place. So let's go back in here and as you can see, each one's on its new, its own line now, a little bit easier to read. And you can see I have lots of options here. Now, let's start turning this into a script. I'm going to use my shebang line. You always want this when you're writing out some scripts. Then bash saying this is a bash script. And I'm gonna come down here and after all my variables, I'm just going to say echo. And the way we'll use this is if we look up here, the way they have it set up is all lowercase variables are for the text itself. Uppercase variables are for the background. So if I wanted the text to be read, I would just say dollar sign red or in this case, I'm using curly braces so I can put my string right up next to it. So what I'm gonna do here is I'm gonna say this is red. Ignore the fact that it's highlighted red inside Vim here. Let's do another line here. I'll say echo and I'll say dollar sign. And inside the curly braces, I'll say blue and I'll say this is blue. And I can say echo, curly braces. And again, you don't have to have the curly braces there, it's just, if I do it without the curly braces and I say this is green, what's going to happen is it's going to have a space before the words and I don't necessarily want that. And since my text and my terminal is already a green color, let's do something else. I'll say purple. And if this say purple. Now, at this point, if we ran our script when it was done, our command prompt might still be purple and we don't necessarily want that. So what we're gonna do is we're gonna say echo and we're just gonna say dollar sign normal and that should put everything back to normal settings. So you'll always want to have that after changing stuff. It doesn't matter, we don't have to do that at the end of each line because we're just issuing a new color or replacing the old color. So now that we have that, let's change mod plus x to make this script executable. And we're gonna say dot slash, the name of our script and hit enter. And as you can see, we got this is red, this is blue, we got this is purple, and then we got a blank line. Now again, we have this extra space here because I didn't use the curly braces and I had to put a space in there. And this empty line is because of our normal line. So let's do something here and fix that as well. Let's go back into our script. Again, what we can do here, the reason we have that space being in that one line is because of that right there. But if we were to remove that, it see it changes color, it doesn't know where the variable's ending. This, these curly braces are just saying, the variable begins and ends here. And to avoid that new line, I think if I just do dash and it will avoid a new line there at the end there for the empty one. So let's save that. We don't need to change modded again because we've already made it executable on our system. So all we have to do is run it again. And there we go, we have this is red, this is blue and this is purple. No extra spaces, no extra lines. Let's go back into our little script here and add something else. Let's say we wanted this purple to be underlined as well. We can say dollar sign and inside curly braces, we can say underline. Because as you can see, if we look up here somewhere, he'll have underline. You also can also make the text bold, strike through a bunch of different stuff. So let's go ahead and have this saved, run it again. And we can see that now we have this is red, this is blue and this is purple and the purple is underlined. And because we have that normal line, everything goes back to normal after that. Now I wanna point out that if we were to add another line here and we were to say echo another line, sure, save that and run it again. You can see that that line is also purple and underlined. And because we didn't clear it out, if we were to make it a different color, let's say gray, it will now be gray, but it's still underlined. So at any time that you're unsure, what you should do is put in a new normal line and actually we don't have to do a whole new line. We can just say here dollar sign normal before our gray. So it's resetting it back to the normal settings and then making it gray. Therefore clearing out any other settings we've set. So there we go, we have our gray text at the end there that's not underlined. So I thought I would share that with you. Again, I didn't come up with this idea, but I think it's a great idea. I'll try to remember to put a link in the description to it on Reddit. Did I say Reddit earlier? I think I might've said GitHub or something, but it was on Reddit. And he explains it here. He gives some examples and this is the one liner that you would put into your code. Someone also wrote out something else here. I haven't tried that, but this guy's one liner works great for me. Want to make sure to give him credit. So I'll be sure to try to put a link in the description. Otherwise you can probably search it on Reddit. Easy colors for shell scripts. Color library is what he called the post. And this is how you use it. I will put a link in the description. I actually, before I did this, I created another color test. Same exact script, except I added a couple other stuff like strike through. You can do a line through stuff. So let me run that actually. I'll save this and I'll say color test. And you can see, I don't think I did any background stuff in the example I showed you. But again, if you do capital green example here, a lowercase green would change the font. The capital green here will make the background green. And again, I'm setting normals in certain spaces. Strike through is a line through your text like it's being crossed out. I'll post this on Pay Spin and hopefully remember to put a link to that in the description of this video as well. And as always, I hope you enjoyed this tutorial. I thank my Patreon supporters for their support and voting on the topic of shell scripts for this month. I hope that you're finding these tutorials useful. As always, please visit filmsbychrist.com. That's Chris with the K. There should be a link to that in the description. And as always, I hope that you have a great day. I would like to take a moment to thank the following patrons who made this video possible by supporting me over at Patreon.com forward slash metalx1000. Right, I don't know. Yeah, and what you were thinking, I would have to write. Yeah, yeah. And so your argument was, well, this is written in C and my argument was, well, everything's written in C. Any scripting language, Python. If you enjoy my tutorials and would like to see more, please think about contributing to my Patreon account at Patreon.com forward slash metalx1000.