Monash University · FACULTY OF COMPUTER SCIENCE

FIT2109 Chap.1 Shell Foundations

- one subject, every graph, every model, every mark
8 Chapters3-page Bible
Our own words - no uploaded lecturer files
Updated for this semester
Chapter 1 of 12 · FIT2109

Shell Foundations

Shell Foundations introduces a command as an observable process with arguments, a working directory, input, ordinary output, diagnostic output and an exit status. The key skill is not recalling isolated commands.

It is predicting which path will be resolved, which stream will carry each line and what evidence distinguishes a location error from a permission or routing error.

Use a disposable directory for practice. Create small files whose contents you know, move between directories and predict the absolute target of each relative path before running a command.

Keep standard output and standard error separate so a data file cannot silently absorb a diagnostic. These habits support the scripting, remote-work and debugging topics that follow.

In this chapter

What this chapter covers

  • 01

    The shell as a program interface rather than a list of shortcuts

  • 02

    Absolute and relative paths interpreted from the working directory

  • 03

    Arguments, quoting and the difference between grouping and validation

  • 04

    Standard input as the default data source for a command

  • 05

    Standard output as the intended result channel

  • 06

    Standard error as a separate diagnostic channel

  • 07

    Exit status as a compact success or failure signal

  • 08

    A location-first method for investigating missing resources

Worked example · free

Trace a relative path failure

Q [6 marks]. A student is in /srv/lab/project and runs ./tools/check.sh data/run.log. The existing file is /srv/lab/project/input/run.log. Explain the failure, correct the invocation and describe safe script behaviour when the path is invalid. The mark allocation here is not a published University scheme; AskSia includes it to organise path-tracing practice.
  • +1State that the relative argument is interpreted from the current working directory.
  • +1Resolve the supplied argument to /srv/lab/project/data/run.log.
  • +1Compare that target with the actual input path under the input directory.
  • +1Correct the call to use input/run.log while preserving the project layout.
  • +1Require the script to validate the path before reading and print a concise diagnostic to standard error.
  • +1Return a non-zero status so callers can distinguish failure from an empty valid result.
The shell passes data/run.log as a relative argument, so the program resolves it from /srv/lab/project and looks for /srv/lab/project/data/run.log. That target does not exist. Calling the script with input/run.log reaches the actual file. The script should validate the resource, send a useful diagnostic to standard error and return non-zero instead of continuing with empty input.
Sia tip — Write the working directory and resolved target on separate lines. If those two lines are wrong, adding permissions or changing the program will not solve the location error.
Glossary

Key terms

Working directory
The directory used as the starting context for a relative path. Print or verify it before diagnosing a missing target.
Absolute path
A path anchored at the filesystem root. It identifies a location independently of the process working directory.
Relative path
A path interpreted from the current working directory. The same text can therefore resolve to different targets in different contexts.
Standard input
The default stream from which a command reads data. It may come from a terminal, file redirection or another command.
Standard output
The stream intended for a command's successful result. It can be displayed, redirected or piped to a consumer.
Standard error
The separate stream intended for diagnostics. Keeping it distinct protects machine-readable output from accidental error text.
Exit status
A numeric process result used by shells and scripts to distinguish successful completion from a failure condition.
FAQ

Shell Foundations FAQ

Why does a relative path work in one terminal but not another?

Relative paths are resolved from each process's current working directory. Two terminals can be in different directories even when they display the same project. Print the directory and resolve the target before changing permissions or code.

Does quoting prove that a file exists?

No. Quoting preserves spaces and special characters inside one argument, but it does not validate existence, file type, readability or meaning. A robust script quotes expansions and performs those checks separately.

Why keep ordinary output separate from diagnostics?

They serve different consumers. Ordinary output may be redirected into a report or parsed by another command, while diagnostics should remain visible to the operator. Mixing them can corrupt data and hide the reason a command failed.

What should I inspect first after a missing-file message?

Check the current working directory, the exact argument, the path it resolves to and a listing of the expected parent directory. Those observations distinguish a location problem from permissions or application logic.

Study strategy

Assessment move

Build one tiny directory tree and use it for repeated retrieval practice. From several working directories, predict the target of a relative path, then verify it. Run commands that produce both a result and a diagnostic and route the streams separately. Add filenames with spaces to practise quoting without confusing quoting with validation.

For every failure, write a short diagnosis with four parts: the intended target, the resolved target, the observed message and the smallest confirming check. Finish by writing a short script that rejects missing arguments and nonexistent paths before reading data, prints diagnostics to the correct stream and returns a meaningful status. Explain the script aloud without relying on command history.

The goal is to make context and dataflow visible, because later pipelines, remote sessions and debugging tasks reuse exactly that model. Add one exercise where a path exists but is the wrong type, and another where output succeeds while a diagnostic is also emitted. Predict the status and both streams before running either case.

This separates resource validation from stream routing and gives you evidence for the two failure families that otherwise look similar on screen.

Working through Shell Foundations in FIT2109? Sia is AskSia’s AI Computer Science tutor — ask any FIT2109 Shell Foundations question and get a clear, step-by-step explanation grounded in how FIT2109 is taught and assessed. Read this chapter free, then take your hardest questions to Sia.

Keep going — explore the course
A+Everything unlocked
Unlocks this Bible + all 167 of your Monash University subjects - and 1,000+ Bibles across every Australian university.
Sia - your FIT2109 tutor, unlimited, worked the way the exam marks it
The full 3-page Bible + practice bank with worked solutions
Chrome extension - sync your LMS so Sia knows your deadlines
Bilingual EN / Chinese on every Bible and every Sia answer
$0.99 Trial
30-day money-back · cancel in one tap · how it works