Linux Shell Scripting - Basics

From zero to scripting8 H 45 M

In this course, take a look at some basic scripting practices in Linux like script file formats, working with variables, loops, script control, and more.

Just you? Training a whole team? There's an ITProTV plan that fits.

Start Training Today
  • Basic Script Building
    • Overview
    • Basic Script Building
  • Using Variables
    • Using Variables
  • Performing Math
    • Redirection
    • Performing Arithmetic
  • Exiting Scripts
    • Conditional Statements
    • Conditional Statements Part 2
    • Conditional Statements Part 3
  • Structured Commands
    • Loops
    • Loops Part 2
    • Loops Part 3
  • Handling User Input
    • User Input Positional Parameters
    • User Input Positional Parameters Pt 2
    • User Input Options
    • User Input Options Part 2
    • User Input Read
  • Presenting Data
    • Presenting Data File Descriptors
  • Script Control
    • Script Control
    • Script Control Part 2


5 M

itprotv course thumbnailitprotv course thumbnailitprotv course thumbnail
  • Episode Description
  • Transcript

In this series, Daniel and Don walk you through the fundamentals of bash scripting in the Linux operating system. Watch here as they take you through the fundamentals like: Script file formats, running scripts, working with variables, performing arithmetic, conditional statements, loops, presenting data, taking user input, and script control.

[MUSIC] In this segment we're gonna take a look at what we can expect from our upcoming Linux shell scripting basic series. It's gonna be a lot of fun. I'm looking very much forward to this series. Because I'm very passionate about this stuff. I very much enjoy it. So hopefully you are as well. You've come to the right place. If you want to go, you know what, I'm a Linux user. I've worked with Linux. It's something that I deal with on a daily basis and man, wouldn't it be nice if I could do x, y, or z automatically. Or if this just ran when I needed it to, and I didn't have to deal with it every day. Or, this is kinda clunky. If it only worked this way, it would be a whole lot easier for me. Or I can never remember a said command or I can never remember to fire off said script. What do I do? Well this is the show for you. That's what we're gonna tackle that's what we're gonna take a look at. And we're gonna start with the very basics of Linux shell scripting. We're gonna start you from just being a Linux user taking you to what it takes to build a script even the smallest of ones. And get it up, get it running, get it working and from there we're gonna tackle more complex topics. To start building upon that knowledge of, now that I know what a script is and how it works and then kinda the inner workings of it. Now, what can I do with it? What some of the more power that's underneath the hood there that I can tap into. So we're going to take look at things like looking at variables, which is a very common thing, something we need to know as scripters. We're also going to work with redirection. I'm going to have some output or input going this way and that way for the ends of creating the outcome that we're looking for. So it's another very important thing that's a fundamental skill when it comes to scripting. Redirecting the inputs and outputs from other files or scripts. Also we wanna work with performing arithmetic, mathematical operations. Sometimes that is something that I'm gonna need to do. What if I need to calculate a date or work with a mathematical function inside of a script? That when I reach a certain value something happens. So I gotta be able to tell my scripts how can I work with very basic arithmetic operations, if I can say that, or even more complex stuff with exponents and more floating point type math. We're going to get into that just a little bit. We're also going to get into conditional statements. These are, if this happens then do this. Or if this happens, do this, else if this happens then do this, else if that happens, that kind of structure. Really looking at things logically and making decisions inside of our scripts based off of conditions that have occurred or are going to occur. Right, very very cool, it really opens up the horsepower and the power inside of your scripts if you are able to master that conditional object. We're also gonna take a look at loops kind of building on top of that condition, where we have basic ifs and thens and that kind of stuff. But we're gonna then say well I want to iterate that over and over and over again until a certain condition becomes true. The power of loops that we can do that. The looping is something that you'll wanna get a good grasp of, and it's gonna help you out in very many of the types of scripts that you're gonna be building. What else do we wanna do? We're gonna handle user input. We've got somebody at the end of a keyboard and a screen looking at this thing, working with it, interacting with it. How do we deal with, there are times when I need them to answer a question. I need them to feed the script type of information. Maybe look at this file or output to this file. Options as well. We wanna be able to code in, to work with options. Maybe I wanna do a dash a for all or a dash o for output. The output of our script to a said file, that kind of thing. So we want to be able to work with that. We're gonna show you the fundamentals of getting that operational inside of your scripts. What else do we want to work with, we're gonna go with working with user input. What if I want to read the user? How does the user actually type stuff in, take that into the script, not from the argument's sake. I'm actually calling the script, but the script is running, it is active. It is working and it prompts the user. We're gonna show you guys how to do that as well. We also wanna take a look at presenting data. That is an important part of script writing. Sometimes our scripts are going to output or generate output to the user for them to take in and assimilate. How do we properly work with that? How will we make that happen? What are some of the commonalities when doing that type of task? We're going to dive into that. And last but not least, script control. We're not always going to be there when the script is going to run. Sometimes I need it to run at 3:00 AM. What if I'm doing backups? What if I'm running updates and I need to do this when no one is actively working on the system or there are very few people we can work with script control to do that. Working with cron jobs, AT. Also making sure that the priority is there. Maybe this script needs priority over other things. Give it some CPU time, to make sure that it gets that. Also i want to make sure that it doesn't get killed by any other processes. We are going to also show you how to do that with no hang ups,. Very, very cool stuff. So this is the basics, that's what we're gonna work our way through and hopefully by the end of that you'll actually have a pretty good knowledge base to start writing some very useful scripts at that point. So if that sounds like something that might interest you we look forward to seeing you in the upcoming series [MUSIC]