Course / The terminal and the language
Keep a message together
How to fetch and submit this lab
Once: install the tool and connect your account.
curl -fsSL https://gonomicon.com/install.sh | sh
gonomicon loginEach 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 submitGoal
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
=. Writingperson = '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
- Put each piece of text in its own variable with no spaces around the
=, likegreeting='Hello'. Single quotes keep the text exactly as written. - Print a variable with
"$name". The double quotes keep a value likeAda Lovelacetogether as one item.printf '%s, %s\n'fills each%swith one value. - Make two variables,
greetingandperson. Thenprintf '%s, %s\n' "$greeting" "$person"andprintf 'Again: %s\n' "$person".