Scripts used in this Learning Path


LP Scripts
Scripts Used to Create This Course

This brief Course covers some of the scripts covered in the Bash Scripting and Shell Programming Learning Path.


I want to share with you a couple of scripts that I use during the creation of courses like this one. Shell scripts don't have to be long and complex. They can be made up of something that is just hard to remember or hard to type at the command line. Something that would be lengthy at the command line or just something that you happen to do often. 

Every time I record one of these videos, I have to do some audio processing. So I wrote a shell script to take care of that for me. When I record a video, it gets saved in MP4 format. Due to the mic I'm using, the audio is just saved on one channel. I used this script to extract the audio and then convert it to a mono file so that the sound will come out of both speakers. See, I start this script with a shebang, a brief description of what it does, and then I start defining my variables. 

The input file is dollar one, which is what we pass in on the command line. Do use the DIR name command to extract the directory portion of the input file. And this way I can use that directory later on in the script. The base name command as the opposite of the DIR name command, which is it returns the name of just the file without a path. The dash S option in this case just removes the .MP4 suffix. I create a temp file with a suffix of .wave that I'm going to use to extract the audio with. 

And then the out file will consist of the directory name followed by the base name of the file that was passed in. But now it's gonna have the .wave extension instead of the .MP4 extension. So the AB convert command just extracts the audio from the input file and saves it as a wave file. 

Next, the Sox command will take the audio from channel one and then save it to a mono file so that the audio comes up both speakers. 

Next, I display the name of the file to the screen, so I can easily copy and paste it if I want to. 

And finally, I clean up my temp file by removing it. 

This next script takes my slides that are in PDF format and creates a series of P and G files that I can use with my video editing software. Again, the first line is the shebang and then a description of what the program does and even how to use it. And the first thing we do is pass in a PDF file and we assign that to the PDF variable. 

Next, I create a slides variable and I replace the .PDF with -slides.png in the file name. From there, I substitute hyphens for spaces, and then I convert everything to lowercase. Sometimes my PDF files are saved in camel case or upper case or whatever. And I just want these images to be all in lower case. If a path was provided, I just use the base name command to strip that path off because I wanna save these images in the directory that I launched the script in. 

Finally, I use the convert command to do the actual conversion from the PDF file to a series of PNG images. I want to mention that the first three slides commands, there are some bashes items that you can use to do some substitution like a DIR or changing the case and that sort of thing. So if you're not using the baShell, I could have used something like the said tool to do these replacements with ORTR to translate from uppercase to lowercase, for example. I find myself writing shell scripts all the time, especially if I'm going to be doing something more than just a couple of times, or if I have to remember the options for a command that I don't use often. For example, I don't use a V convert during my normal daily activity. So it's hard for me to remember those options since I use them rarely. 

Hopefully you've enjoyed this video and that'll give you some ideas of how you can automate the work that you do.

About the Author
Learning Paths

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 Nothing gives him more satisfaction than knowing he has helped thousands of IT professionals level up their careers through his many books and courses.

Covered Topics