Okay quick summary, because this is good stuff to know. Don't feel too bad though; most of my shell scripting involves a lot of looking things up on Google. :)

`[ -z ... ]` checks if something is an empty string. So this, for example, sets `$MAX_SECS_IDLE` to `1800` if it's not already set:

```sh
if [ -z "$MAX_SECS_IDLE" ]; then MAX_SECS_IDLE=1800; fi
```

`[ -z ... ]` is equivalent to `test -z ...`; try `man test`.

`$(some-command args)` runs a command and returns its output. Same as backticks, but cleaner, and nestable.

Like in most languages `if foo || bar` fires if either `foo` or `bar` is true. In most cases, `foo` and `bar` are commands and we look at their return code; 0 means true, everything else is false (i.e. the command exited with an error). It's backwards, but for good reason.

You can figure out most of the commands, but you probably don't use `expr`; it's a really sucky but widely available command-line calculator that only does integer math (somewhat better is `bc`, but it's not installed by default on the EMR AMIs). Unlike most unix commands, it doesn't have a `-q` flag (i.e. don't print stuff out, just tell me if it worked), which is why I redirected its output into `/dev/null` here:

```sh
if expr $SECS_IDLE '>' $MAX_SECS_IDLE '&' \
    $SECS_TO_END_OF_HOUR '<' $MIN_SECS_TO_END_OF_HOUR > /dev/null
```

Putting commands in parentheses runs them in a subshell (i.e. a subprocess). Which is how `$(...)` works, but is also something I used in my main loop to create a daemon.

Redirects: `> path` (or `1> path`) redirects stdout into `path`, `2> path` redirects stderr, and `&> path` redirects both. `0<` is how you read a file into stdin. `&-` is an evil pretend file that kills file descriptors.

So that final line:

```sh
) 0<&- &> /dev/null &
```

closes stdin, dumps stdout and stderr into oblivion, and puts the whole subshell in the background (the final `&`). On Linux, this makes a daemon; on some unixes you have to `nohup` as well, but Linux doesn't HUP anyway.