Please enable JavaScript eh!

 Web Mechanic 

Bash Scripting

 BASH Programming on macOS 

Yes, this site is all about programming with bash! Sorry, I should have warned you.

/usr/bin/ruby
/usr/bin/perl
/usr/local/bin/bash

Those are some of the programming tools available to most Mac and Linux users.

The path '/usr' is not spelled wrong - it stands for Unix System Resources.

The menu block above (JSON), is displayed as a serialized path, but you can jump in wherever you need.

Programming in general is about solving problems. When you think about all the applications that you have access to on your computer, phone, or tablet, consider the various jobs they are doing.

Something like your Contacts application is a good example:
• It allows you to enter a name and other details about someone.
  How do they do that?
• You can sort your list of contacts by several ways.
  How do they do that?
• You need a hard copy of your Contacts, so you print it out.
  How do they do that?

The How do they do that? part is the problem. Programming is the solution.

That is a particular type of programming, but not what we're going to discuss here. Imagine something you do every day or every week with your computer. It may take only a short time, but every time is the same thing, with maybe some minor changes.

These are the kinds of things shell programming is designed for.
Any repetitive task on a computer is an ideal candidate for shell programming.

If you've worked with Windows, Linux or a macOS computer, you may have heard about shell programming or scripting. If so, and you are interested in learning some things about it, read on.

I work in an Apple environment, with an iMac 24" M1 as my main development box. As such, whatever you read here has been done by me on my computer. It may work the same on a Linux box, but there may be some differences. After all macOS is based on the Unix OS.

When I first encountered an Apple computer, I knew nothing about shell programming, but I had spent several years in the Microsoft environment, and was quite comfortable with batch files. Scripting with BASH is essentially the same thing, but I had to learn this stuff too, so don't feel bad.

The shell we will be looking at here is the bash shell. Sometimes known as BASH because it is actually an acronym for Bourne Again SHell. One of those nerdy computer things.

I use lower-case bash instead of BASH because I'm a lazy typist.

Have fun; be patient; measure twice, cut once.

bash or zsh