Skip to content
Kenny Yu edited this page Sep 25, 2013 · 9 revisions

What is a shell script?

So far, all the commands you've been writing were only executed in the terminal. Often, however, you want to save the commands so that you can use them later. We can do this by writing a shell script! A shell script is essentially a sequence of commands that you would normally just type into the command line, but saved into a file. Let's take a look at our first shell script!

First, make sure you already have the source code for this bootcamp:

git clone git://github.com/hcs/bootcamp-setup.git
cd bootcamp-setup

There should be a scripts directory that will contain the examples from this part of tutorial. You'll be able to run all the examples from that directory.

cd scripts

Take a look at our first script hello.sh (type cat hello.sh to dump the contents of the file, and ./hello.sh to run the script).

#!/bin/bash

echo "Hello bootcampers!"

Notice the #!/bin/bash at the very top. All shell scripts must start with this!!!. Also, if you run the command ls -l hello.sh, you'll see this:

-rwxr-xr-x  1 kennyyu  staff  39 Sep 24 22:59 hello.sh

Notice the x's. All shell scripts must have executable permissions!!!. Remember that to add executable permissions to a file, use chmod +x FILE.

explain the scraper

#!/bin/bash

loops variables mail merge example semicolon