>_ IzzyLab

Hands-on task

This task is step 7 of the course “Troubleshooting and recovering a Linux server”

A broken PATH breaks the script

medium~7 min

The script /opt/tool/deploy.sh fails with "command not found" on the mytool utility, even though it's installed in /opt/tool/bin. The problem is the PATH inside the script. Fix it so deploy.sh runs successfully.

What you'll practise:
  • path
  • environment variables
  • command not found
  • shell scripts
  • executable lookup

Topic breakdown

When a command is called by its short name, the shell looks for the executable only in the directories listed in the PATH variable — "command not found" almost always means not "not installed" but "not where the shell is looking". This has to be fixed in the environment of the process that runs the command (inside the script itself), not in your personal .bashrc: the runner's non-interactive process won't pick up your interactive shell settings. The key principle is to extend PATH by appending the new directory to the existing value (PATH="new:$PATH") rather than overwriting it entirely, otherwise the other utilities will stop being found; the alternative is to reference the binary by its full path.

What's checked

  1. deploy.sh runs with the system PATH
  2. deploy.sh still calls mytool
  3. mytool not planted in system directories

What it looks like