Course outline
Course / The terminal and the language

Keep a message together

Lab

How to fetch and submit this lab

Once: install the tool and connect your account.

curl -fsSL https://gonomicon.com/install.sh | sh
gonomicon login

Each lab: download it, edit the file named in the instructions, then submit.

gonomicon fetch week-1/04-01-shell-variables-and-quoting
cd 04-01-shell-variables-and-quoting
gonomicon submit

Go installed? gonomicon test runs the visible test on your computer first. Submitting also runs hidden checks on our server.

Goal

Store a greeting and a full name in shell variables, then print two lines that use them. The name contains a space, so it has to stay together as one value.

Example

If your variables held Good day and Sam Lee, a script that prints one line in each of the two shapes below would print:

Good day, Sam Lee
Again: Sam Lee

Your script uses Hello and Ada Lovelace instead, so the lines it prints are different from this example.

Rules

  • Edit answer.sh. It has no input files. Everything it needs is inside the script.
  • Create one variable for the greeting (Hello) and one for the name (Ada Lovelace).
  • Print exactly these two lines, in this order, using printf:
Hello, Ada Lovelace
Again: Ada Lovelace
  • Write the name only once in the script, inside its variable. Use "$name" (with double quotes) both times you print it.
  • Assignments have no spaces around =. Writing person = 'Ada Lovelace' fails.
  • Do not print anything else, not even a blank line.

What you'll practice

Variables, single quotes and double quotes, and printf with %s.

Run it

gonomicon fetch week-1/04-01-shell-variables-and-quoting
cd 04-01-shell-variables-and-quoting
gonomicon test
gonomicon submit

Hints

  1. Put each piece of text in its own variable with no spaces around the =, like greeting='Hello'. Single quotes keep the text exactly as written.
  2. Print a variable with "$name". The double quotes keep a value like Ada Lovelace together as one item. printf '%s, %s\n' fills each %s with one value.
  3. Make two variables, greeting and person. Then printf '%s, %s\n' "$greeting" "$person" and printf 'Again: %s\n' "$person".

Something wrong with this lesson? Report a problem