Just launched! Get 30% off The Imposter's Frontend Accelerator Get It Now

Shell Script Basics

7 years ago | Command Line Videos
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.

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

IMAGES=$(ls ./images/**/*.jpg ./images/**/*.png)

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

mkdir "$DIST"

for IMG in $IMAGES
    convert $IMG -resize 600x400 "$DIST/$(basename $IMG)"

There's More...

The Imposter's Frontend Accelerator

JavaScript client frameworks are powerful and help you create an amazing experience for your end user. Unfortunately, learning how to use them sucks.

🤖 A Real World Approach to Playwright

Writing tests can be tricky, especially using a more complex tool like Playwright. I took some time and dug in over the last year and I'm happy I did.

What Is Your Yeet Threshold?

Solving problems is what we do, but sometimes the solution is to burn it all down and start again, learning from your mistakes. How do you make this choice?