This video is free to watch - hope you enjoy it! If you like what you see, there's a ton more where that came from...

Sign Up

Shell Script Basics

It's a Unix world. You should have a functional knowledge of how to get around a Unix machine using the command line, as well as how to complete basic tasks using shell scripts and Make files.

This content is for subscribers only - which you can become in just 30 seconds!

Sign Up

Shell scripts can help make tedious programming tasks routine, like renaming/resizing images. Make is an old, reliable build tool that can replace (easily) Grunt, Gulp, Rake, Jake and any other language-dependent build tool.

As a developer, having a set of scripts, aliases and binaries in your “dotfiles” is a great way to organize the tools that help you on a daily basis.

Why Do You Have a Section On Unix and Shell Scripts?

The simple answer to that is that there are many, many, many developers who stick to the GUI. They prefer apps and tools to commands. They click “File” and “Edit”, hunting for “Copy” and “Paste”.

You know these people. You were one of these people. This isn’t a judgement of any kind; I stick to the GUI myself far more than I’d care to admit. There’s a better way, a faster more efficient way to work with a computer, and you’ll be a better programmer all around if you learn some basic shell skills.

Unix and Unix-like systems (Linux, BSD, Solaris, RedHat, etc) have been around forever. You simply can’t expect to grow much in your career if you don’t have a basic competency with Unix and its commands. If you don’t believe me, skip right over this chapter. It’ll be here when you come back, after you’ve realized just how true this is.

This is an exciting thing! Crawling under the hood of your computer can increase your efficiency dramatically. Shell scripts, Makefiles, server setup routines, quick little commands to update your system, configuring your web/database server remotely over SSH … these are skills you must know.

So let’s wander through the shell. I won’t go into Unix history as I’m just not qualified to do so. I’ll also sidestep the basics of the Unix commands – that’ll be up to you.

Instead, let’s get right to the thing that will help you the most in your job: basic shell scripting skills.

The Code

#!/bin/sh
IMAGES=$(ls ./images/**/*.jpg ./images/**/*.png)
DIST=./dist

if [ -d "$DIST" ]; then
	rm -R "$DIST"
fi

mkdir "$DIST"

for IMG in $IMAGES
do
	convert $IMG -resize 600x400 "$DIST/$(basename $IMG)"
done
  • Design Patterns: Creational

    Tried and true design patterns for creating objects in an object-oriented language.

  • Design Patterns: Structural

    As your application grows in size you need to have a plan to handle the increase in complexity. The Gang of Four have some ideas that could work for you.

  • Design Patterns: Behavioral

    Mediators, Decorators and Facades - this is the deep end of object-oriented programming and something you'll come face to face with as your application grows.

  • Principles of Software Design

    You've heard the terms before: YAGNI, SOLID, Tell Don't ASK, DRY... what are they and what do they mean?

  • Testing Your Code: TDD and BDD

    Testing code has moved beyond the realm of QA and into the realm of design, asking you to think about what you do before you do it. Let's have a look at some strategies.

  • Shell Script Basics

    It's a Unix world. You should have a functional knowledge of how to get around a Unix machine using the command line, as well as how to complete basic tasks using shell scripts and Make files.

  • Hands On: Creating a Useful Shell Script

    I use the static site generator Jekyll to write my blog. I store the site at Github, who then translates and hosts it all for me for free. Jekyll is simple to use and I like it a lot. There's only one problem: it's a bit manual.

  • Deciphering a Complex Bash Script

    I use the static site generator Jekyll to write my blog. I store the site at Github, who then translates and hosts it all for me for free. Jekyll is simple to use and I like it a lot. There's only one problem: it's a bit manual.

  • Making Your Life Easier with Make

    Make is a build utility that works with a file called a Makefile and basic shell scripts. It can be used to orchestrate the output of any project that requires a build phase. It's part of Linux and it's easy to use.

  • Using Make to Improve Your Test Suite

    Make has been around forever and is often overlooked in favor of tools that recreate precisely what it does, but in crappier ways. Let's see how you can use Make to help your testing process.

Watch Again

[[prev.title]]

[[prev.summary]]

Next Up

[[next.title]]

[[next.summary]]