# Exercise: A Morning Start-Up Script

Write morning.sh, a script that greets whoever runs it and shows the date, the to-do list and the free disk space, make it runnable, turn it into a command called morning, and let a check script run it from another folder to tell you what's done.

Apprentice · Unix · Linux · Updated November 10, 2026

Your mornings start with the same small jobs: a hello, the date, your to-do list, and a look at the free disk space before it fills up and surprises you. This exercise turns those jobs into an application of your own: a script, `morning.sh`, that does all four, and then a command, `morning`, that runs it by name. A check script runs your command the way a stranger would, from another folder and under another user name, and tells you which parts are done.

## Before you start

You need a terminal: the Terminal app on a Mac, or Ubuntu on Linux or in WSL on Windows. The check runs with **bats**, a small program that runs checks written for bash. If `bats --version` doesn't print a version number yet, install it:

```bash
sudo apt install bats       # Ubuntu, and Ubuntu in WSL
brew install bats-core      # a Mac, with Homebrew
```

`sudo` asks for your password, the one you use to sign in; nothing shows on the screen while you type it. **On Windows, keep the exercise inside Ubuntu**, in your Linux home folder, not in a Windows folder under `/mnt/c`: Windows folders don't keep the `x` that `chmod +x` adds.

## Get the exercise code

Open this lesson's GitHub repository, [github.com/ask-codey/exercise-bash-a-morning-start-up-script](https://github.com/ask-codey/exercise-bash-a-morning-start-up-script), also linked from the **Exercise** box beside the lesson. Click **Code**, then **Download ZIP**, and unzip it into your `terminal-practice` folder as `exercise-bash-a-morning-start-up-script`. Or clone it with Git.

The folder holds:

- `morning.sh`: your script, with only a few comments in it for now. This is the file you write.
- `bin/`: stands in for your `~/bin`, so the check can see your command. Your copy goes here.
- `todo.txt`: a sample to-do list.
- `answers.txt`: three questions, each with a numbered line for your answer.
- `check.bats`: the check. You don't need to change it.

Your script reads the to-do list from `~/terminal-practice/morning/todo.txt`, the one you made in *Your First Script*. If you don't have it, copy the sample there:

```bash
mkdir -p ~/terminal-practice/morning
cp todo.txt ~/terminal-practice/morning/todo.txt
```

## What to do

Open a terminal and `cd` into the exercise folder (the one with `answers.txt` in it). Then work through the jobs:

1. **Write the script.** Open `morning.sh` in nano (`nano morning.sh`) or in VS Code (`code .`), delete the comments that are there, and write your own: the shebang on line 1, a comment saying what the script does, and then commands that greet whoever runs it, show today's date, show the to-do list and show the free disk space (*Your First Script*).
2. **Let it run.** `chmod +x morning.sh`, then `./morning.sh`. Read the output: is everything there?
3. **Run it from somewhere else.** `cd ~`, then run it by its full path. If the list is missing, the path inside the script only works from its own folder (*Run It from Anywhere: ~/bin on Your PATH*).
4. **Make it a command.** Back in the exercise folder, copy the script into `bin/` as `morning`, without the `.sh`. Put that folder on your PATH for this terminal with `export PATH="$PWD/bin:$PATH"` (`$PWD` holds the folder you're in), then `cd /tmp` and type `morning`.
5. **Answer the three questions** in `answers.txt`, about naming and permissions.

The file starts like this:

```text
# Example: what is the name of the file your script is written in?
# 0) morning.sh

# 1. You'd like to name a script test. What kind of command is test already? (type test tells you.)
1)
```

If you use VS Code with ShellCheck, look for underlines as you type, and fix any it shows (*Writing Scripts in VS Code*).

## Check your work

From the exercise folder:

```bash
bats check.bats
```

At first most checks fail. That's expected: each job you finish turns its check into a ✓. A failing check names the job and gives a hint, for example *From another folder, the script couldn't find the to-do list. A script runs in the folder you're in, so start the path with ~: cat ~/terminal-practice/morning/todo.txt*. To be fair to every computer, the check runs your script with a pretend home folder holding a to-do list of its own, as a user named `maya`, so your real files are never touched.

## Hints

- **Greet `$USER`**, not your own name: the check runs the script as `maya`.
- **Show the list from its file** with `cat`. Typing the list's lines into the script won't pass: the check's list is different from yours.
- **Today's date:** `date '+Today is %A, %B %d.'`, or any `date` that shows the day's name.
- **`chmod +x` before you copy:** `cp` keeps the `x`, so the copy may run too. Change the script later? Copy it again.
- **Nothing above the shebang**, not even a blank line or a comment.

## When you're done

Every check passes:

```text
check.bats
 ✓ morning.sh starts with the shebang #!/usr/bin/env bash
 ✓ a comment says what morning.sh does
 ✓ morning.sh may run
 ✓ morning.sh runs without an error, from any folder
 ✓ it greets whoever runs it
 ✓ it shows today's date
 ✓ it shows the to-do list in ~/terminal-practice/morning, from any folder
 ✓ it shows the free disk space
 ✓ bin/morning is a copy of morning.sh, without the .sh
 ✓ morning runs by name from any folder, with bin on the PATH
 ✓ 1) what kind of command test is
 ✓ 2) morning.sh's permissions
 ✓ 3) the command that shows whether a name is taken

13 tests, 0 failures
```

Now make it yours for real: copy `morning.sh` into your own `~/bin` as `morning`, open a new terminal, and type `morning` tomorrow when you sit down. What else would you like it to show you each morning?

## Submit your exercise

The exercise is how you finish this lesson. When your work is done, put it on GitHub in a repo of your own, then submit that repo's address here.

1. On GitHub, click **+**, then **New repository**. Name it (for example `exercise-bash-a-morning-start-up-script`), choose **Public**, and click **Create repository**. Leave out the README: your folder already has one.
2. In a terminal in your exercise folder (Ubuntu in WSL on Windows), send your work to your new repo. If you downloaded the ZIP:

   ```bash
   git init -b main
   git add .
   git commit -m "My solution"
   git remote add origin https://github.com/your-name/exercise-bash-a-morning-start-up-script.git
   git push -u origin main
   ```

   If you cloned the starter instead, point your copy at your own repo, then commit and push:

   ```bash
   git remote set-url origin https://github.com/your-name/exercise-bash-a-morning-start-up-script.git
   git add .
   git commit -m "My solution"
   git push -u origin main
   ```

3. Paste your repo's address, such as `https://github.com/your-name/exercise-bash-a-morning-start-up-script`, into **Submit your exercise** on this page. The site checks that the repo is public and holds your commits, and then the lesson is complete.

Changed something after you submitted? Push it, and submit again: your latest submission is the one that counts.

## So what

You've written an application, made it runnable and given it a name that works from any folder: the same steps that turn every script, from a morning check to a whole expense tracker, into a tool you'll use for years.

## Key terms

- [Shell Script](https://www.ask-codey.com/glossary/shell-script)
- [Shebang](https://www.ask-codey.com/glossary/shebang)
- [chmod](https://www.ask-codey.com/glossary/chmod)
- [PATH](https://www.ask-codey.com/glossary/path-unix)
- [~/bin](https://www.ask-codey.com/glossary/bin)

## Related

- [A Script Is an Application](https://www.ask-codey.com/lessons/bash-scripts-are-applications)
- [Your First Script](https://www.ask-codey.com/lessons/bash-your-first-script)
- [Run It from Anywhere: ~/bin on Your PATH](https://www.ask-codey.com/lessons/bash-scripts-on-your-path)
- [Writing Scripts in VS Code](https://www.ask-codey.com/lessons/bash-scripts-in-vs-code)

Source: https://www.ask-codey.com/lessons/exercise-bash-a-morning-start-up-script
