This course wraps up the Linux Shell Scripting learning path and recaps what you've learned.
At the beginning of the of course you started learning about the absolute necessities when it comes to shell scripting. You found out that it really doesn't matter what the file name of the shell script is or what extension it has if any, the most important thing is its permissions and specifically the execute permission. You learned how to add executable permissions to your scripts with the chmod command. Once you started writing shell scripts you learned the importance of using a shebang on the very first line of your script. You also learned how to insert comments in your script. You quickly started using variables to store values in your script, you use the echo shell built in to generate standard output, including displaying the contents of variables. You learned that using single quotes around a string makes it a literal string. That means everything in the single quotes is displayed exactly as it appears in your shell script. When you want to allow for variable expansion you learned to use double quotes. You learned how to use the type command to determine if a command is a shell builtin or a Linux command. To get help on a shell builtin, you use the help shell builtin command. For Linux commands you learned how to use and read man pages. You also learned how to take advantage of some of the shell variables that you get for free when using bash. Some of the variables you've used included host name random and UID. We talked about command substitution and how the dollar sign parentheses syntax is the current favored way to perform that command substitution while surrounding a command in back ticks is the older syntax that you may still encounter from time to time. You assign the output of commands to variables using this method, as well as using the output of those commands directly, or as part of other commands. Once you started creating scripts ahead multiple steps and requirements, you were introduced to the concept of pseudo coding, which is simply a high level description of what your script will do. You then went back over your steps and filled in the exact commands and details required to make those steps function correctly. You also learn how to use an if statement. We talked about how you can use expressions and operators supported by the test built in between the double brackets of the if statement. We also talked about the older syntax of using single brackets for conditional expressions. The use of the if statement brought us to exit statuses that's because the if statement was checking to see if an expression was successful or not before it executed the appropriate code block. When a command complete successfully, it returns an exit status of zero. When it doesn't, it returns a non-zero exit status. You learned how to control the exit status of your scripts by using the exit shell builtin you also learn how to check the exit status of the most recent command by examining the contents of the variable dollar sign question mark, you use the if statement to perform some sanity checking. Users don't always behave the way you want them to and systems are not always configured exactly the same. If something is required for your script to execute successfully you learned that you have to check for it. When you started using multiple options to various commands, we talked about how you can combine multiple single character options following just one hyphen. For most options, the order doesn't matter so you can execute the same command in multiple ways and still get the exact same result. Also many commands give you the option of using a single character option or a longer version of that option. When there are two forms of the same option, such as dash n or dash dash name, you only need to use one of the forms. By the way, all the variations of the ID command you see here on your screen are equivalent and produce the exact same output. Next, you learned how to use the read shell builtin in order to capture standard input and store it in a variable, you then moved on to creating random data that you could use for account passwords. One way you did this was by taking advantage of the random shell variable. Another method you used was to take the output of the date command and run it through a cryptographic hash function. You then started working with positional parameters. You learned that arguments are what are supplied to your script, and that parameters are what you use to store those arguments inside of your script. Not only did you learn about dollar $0, $1 and so on, you learned about a few special parameters such as dollar sign asterisk, dollar sign add sign and dollar sign pound sign, because you can can't always anticipate the number of arguments a user may supply to your script. You used a for loop to loop through each of the positional parameters. You also learn how to create while loops while the test returns true, the code block between do and done will be executed. This means that during the while loop you'll want to change the thing being tested for in some way so that the condition eventually evaluates to false or you'll end up in an infinite loop. Finally, you learned how to fully manipulate standard input, standard output and standard error by using I/O redirection. One of the first forms of I/O redirection you used came in the form of a pipe. You took the standard output of one command and piped it as the standard input into another command. You were able to start with some output and by making small changes through a series of pipes you were able to put it in the exact format that you wanted. Next you covered I/O redirection, to and from files. You learned that using a single greater than sign when redirecting will create a new file or overwrite the existing contents of a file if it already exists. In order to append to a file without overwriting it you use the double greater than sign syntax. You redirected the contents of a file a standard input into a command by using the less than sign. You also learned how to send standard error to a file as well as how to send both standard output and standard error to a file. You continued working with pipes and learned how to send both standard output and standard error as standard input through a pipe by using the pipe ampersand syntax. In order to conform to the convention of sending error messages to standard error you learned how to redirect standard output to standard error. You also learned how to discard output by sending it to the null device. I hope you realize how far you've come in a relatively short period of time. At this point, you could easily go off and write all kinds of useful shell scripts. You know how to control the flow of your scripts, you know about input and output redirection, you know how to perform loops, you understand many shell scripting conventions and on and on. In short, if you've completed this course you are so far ahead of most shell scripters. However, I encourage you to keep learning and practicing. Of course, one of the best ways to do that is to use your skills to perform some real world work that you need to get done. Pick something that you need to automate or make easier be it something you do at home or at work. Finally, I wanna congratulate you on completing this course. It's so easy to start something yet so hard to finish it. If you've made it this far, know that you're one of the few who see things through to the end. For that, I really respect you. I wish you the best. And I hope to see you in another one of my courses soon.
Jason is the founder of the Linux Training Academy as well as the author of "Linux for Beginners" and "Command Line Kung Fu." He has over 20 years of professional Linux experience, having worked for industry leaders such as Hewlett-Packard, Xerox, UPS, FireEye, and Amazon.com. Nothing gives him more satisfaction than knowing he has helped thousands of IT professionals level up their careers through his many books and courses.