>_ IzzyLab

Hands-on task

This task is step 4 of the course “Clean scripts: shellcheck”

Replace the deprecated backticks

medium~5 min

The script /root/stamp.sh writes the current date to /root/out.txt, but it uses the deprecated backtick command substitution, which shellcheck warns about. Rewrite the substitution using the modern syntax so that the linter stays silent and the script still writes the date.

What you'll practise:
  • shellcheck
  • command substitution
  • $(...)
  • bash
  • linting

Topic breakdown

shellcheck is a static analyzer for bash scripts that catches common mistakes and assigns each its own SCxxxx code. Warning SC2006 concerns the deprecated backtick command substitution: it has a modern written form that reads more clearly and nests correctly within itself. The point of the task is to understand that command substitution has two equivalent forms and to switch from the old one to the new one without changing the invoked command itself.

What's checked

  1. shellcheck without warnings
  2. script writes the date

What it looks like