Skip to content
Clairos Learn

Shell scripting · Lesson 29 of 31 · 8 minutes

Script path resolution

Resolve script paths and report their directory and basename.

Mastery 0/3Run itExplain itApply it
learner@clairosSimulated Linux lab
learner@clairos:~ $
↑ history · Tab complete · Ctrl+C cancel · Esc, Tab to leaveExit 0

Understand the pattern

Handling script paths without depending on the current directory helps operators explain what they know before they change anything.

realpath
Resolve a path to its canonical location in the virtual filesystem.

Resolving a path and reading its contents are separate operations.

basename
Remove directory components from a path string.

String manipulation does not verify that the target exists.

dirname
Extract the directory portion of a path string.

A path can be syntactically valid without naming an existing directory.

Worked example and expected result
$ realpath scripts/deploy.sh
/home/learner/scripts/deploy.sh

Exit status: 0. The command completed successfully in the training fixture.

$ basename scripts/deploy.sh
deploy.sh

Exit status: 0. The command completed successfully in the training fixture.

$ dirname scripts/deploy.sh
/scripts

Exit status: 0. The command completed successfully in the training fixture.

Try a variation

Repeat this workflow in the sandbox with a different scratch filename. Keep the system fixtures unchanged and compare the observed output with your expectation before moving on.

Explain it

In “Script path resolution”, which interpretation is safe?

Apply it elsewhere

Before adapting the basename workflow from “Script path resolution” to another server, what should you do?

Keep the momentum.

Complete the lab, then explain and apply the pattern.

Next: Script change reviewTry an incident drill

Anonymous lesson and mastery progress lasts for this session. Sign in to keep synced lesson XP between sessions; mastery stays device-local. No speed bonus, lost lives, or hint penalties.

Keep learning

  1. 01Predictable output contractCreate machine-readable status lines and verify their shape.Practice
  2. 02Script change reviewCompare configuration snapshots and record a review marker.Practice
  3. 03Shell workflow bridgeCheckpoint guards, path handling, output contracts, and change review.Practice