Exercise: Your Practice Folder

Put this exercise in your practice folder, answer three questions about your own terminal, make a folder whose name has a space, and let bats check that your computer is ready for the course.

Novice · Unix · Linux · Updated

Before you build anything, make sure your kitchen is set up: the right tools within reach and a counter cleared to work on. This exercise does that for the terminal. You'll put the exercise in your practice folder, ask your own terminal three questions, and make one folder whose name has a space in it. Then a check script, run by bats, tells you whether your computer is ready for every exercise after this one.

Before you start

Finish your setup lesson first: Setup: The Terminal on a Mac, on Linux or on Windows. It makes your practice folder, ~/terminal-practice, and installs bats, the program that runs the check. If bats --version doesn't print a version number yet, install it:

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

Get the exercise code

Open this lesson's GitHub repository, github.com/ask-codey/exercise-bash-your-practice-folder, also linked from the Exercise box beside the lesson. Click Code, then Download ZIP, and unzip it. Or clone it with Git.

The exercise folder must sit inside your practice folder, so move it there with your file manager. To open your practice folder in the file manager from the terminal, go there with cd ~/terminal-practice, then type open . on a Mac, xdg-open . on Ubuntu, or explorer.exe . in Ubuntu on Windows, and drag the exercise folder into the window.

The folder holds:

  • answers.txt: three questions about your terminal, each with a numbered line for your answer. This is the file you write.
  • check.bats: the check. You don't need to change it.
  • README.md: these instructions, in short.

What to do

Open a terminal and go into the exercise folder. Its name is what ls ~/terminal-practice shows; a downloaded ZIP may add -main to the end:

cd ~/terminal-practice/exercise-bash-your-practice-folder
  1. Ask your terminal. Each question in answers.txt names the command that answers it. Run the command, then write what it tells you after the question's ). Open answers.txt in any text editor: TextEdit on a Mac, Text Editor on Ubuntu, or Notepad on Windows (type notepad.exe answers.txt in Ubuntu). Save after each answer. The file starts like this:

    # Example: which command prints the folder you're in?
    # 0) pwd
    
    # 1. Which shell does your terminal open? Type echo $SHELL and write what it prints.
    1)
    
  2. Make a folder with a space in its name. In the exercise folder, make a folder named my notes (one space, all lowercase), then an empty file named todo.txt inside it. mkdir, followed by a name, makes a folder, and touch, followed by a path, makes an empty file. Both names need care: think about what the shell does with a space.

Check your work

From the exercise folder:

bats check.bats

The first two checks pass as soon as the folder is in the right place. The rest fail until you finish each part. That's expected: each part you get right turns its check into a ✓. A failing check says what to look at, for example Question 3: ~ is short for your home folder. Write the full path that pwd prints, which starts with /.

Hints

  • Copy, don't retype. Select the text a command printed, copy it, and paste it into answers.txt, so nothing gets mistyped.
  • Only the first number is wanted for question 2: the one right after the word version.
  • A full path starts with /. ~ is a shortcut the shell understands, but the check wants the address pwd prints.
  • Spaces split arguments. Without quotes, the shell hands mkdir two names, not one (The Shape of a Command).
  • Made two folders by mistake? They do no harm. Make my notes correctly, and the check passes.
  • A failing "bash 5" check on a Mac means your scripts still run in the Mac's old bash 3.2. Setup: The Terminal on a Mac adds bash 5.

When you're done

Every check passes:

check.bats
 ✓ bats is installed and running your checks
 ✓ this exercise is inside your practice folder
 ✓ 1) the shell your terminal opens
 ✓ 2) the version of bash that runs your scripts
 ✓ bash 5 or newer runs your scripts
 ✓ 3) the full path of your practice folder
 ✓ "my notes" is one folder, with todo.txt inside it

7 tests, 0 failures

Now look back at question 3. Your answer is the same address as ~/terminal-practice, written out in full. Which would you rather type, and which one would still be right on a friend's computer?

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-your-practice-folder), 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:

    git init -b main
    git add .
    git commit -m "My solution"
    git remote add origin https://github.com/your-name/exercise-bash-your-practice-folder.git
    git push -u origin main
    

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

    git remote set-url origin https://github.com/your-name/exercise-bash-your-practice-folder.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-your-practice-folder, 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

A ready terminal, a practice folder to work in and a check you can run yourself are the setup for every exercise in this course, and the same habit every developer has: get the workbench ready, then build.

Key terms

Related