>_ IzzyLab

Hands-on task

This task is step 10 of the course “Bash: expansions, arrays and quoting”

Quotes save the asterisk

medium~5 min

The script /root/banner.sh should print its first argument between === markers verbatim: bash /root/banner.sh 'a b' → === a b ===, bash /root/banner.sh '*' → === * ===. Right now it squeezes the spaces, and turns the asterisk into a list of files in the current directory. Fix the script. Open it in the Editor tab above the terminal.

What you'll practise:
  • quoting
  • word splitting
  • globbing
  • parameter expansion

Topic breakdown

After substituting an unquoted variable, bash takes two more steps with the result: splitting into words on spaces (repeats are squeezed) and expanding file name patterns — *, ? and […] turn into a list of matching files in the current directory. Hence two bugs in one line: a b is printed as a b, and * as a list of files. Double quotes turn both steps off while keeping the substitution itself: the value goes out as one argument, character for character. So the rule is simple — always put substitutions in double quotes unless you need the opposite.

What's checked

  1. spaces inside the argument are kept
  2. the asterisk doesn't expand into file names
  3. an ordinary argument is printed between the markers

What it looks like