Practical technology learning
Linux Output Streams: Keep Standard Output, Standard Error and Exit Status Separate
A terminal combines several observations that should be interpreted separately. Use a small Bash script with invented text to distinguish ordinary output, diagnostic output and the process status. Work only in a disposable practice directory and choose new filenames so the exercise cannot overwrite useful files.
Create two visible sample lines
Prepare a tiny local script that writes “sample result” to standard output and “sample diagnostic” to standard error. Use a deliberate explicit exit status so the status does not depend on your assumptions about the wording of either line.
Run it without redirection and note that both lines can appear in the terminal. The display alone does not establish which stream carried each line. Write the expected output destination beside each statement before continuing.
Redirect the streams into separate new files
Run the script with standard output directed to a new results file and standard error directed to a separate diagnostics file. Inspect both files immediately. In Bash, the usual stream numbers are 1 for standard output and 2 for standard error.
Keep the first comparison simple: one input script, one results file and one diagnostics file. Avoid combining streams until you can explain the separate case. A blank terminal is expected when both destinations have moved away from it.
Distinguish replacing a file from appending to it
Using only disposable files, compare output redirection with append redirection. Predict the content after two runs. Replacing a file can discard its previous content; appending can accumulate repeated lines. Neither behaviour should be chosen by accident.
Read the destination filename carefully before executing a command. Do not practise on application logs, configuration, home-directory documents or files containing personal data. The aim is to understand destination behaviour, not to modify a running service.
Treat the exit status as a separate observation
Inspect the command status immediately after the script completes. Compare a controlled run that prints a diagnostic but exits successfully with another run that explicitly exits unsuccessfully. Explain the status from the script’s contract rather than from the emotional tone of a message.
A diagnostic stream can carry information that is not a fatal error. Conversely, absence of a visible message does not prove success. For this exercise record the status, the results file and the diagnostics file as three separate pieces of evidence.
Review the learning record
- Each sample line reaches the intended destination.
- Overwrite and append expectations match the actual files.
- The status is recorded before another command replaces it.
- Diagnostics remain available for inspection.
- All files belong to the disposable exercise.
Extend cautiously after the separate-stream test
Read Bash’s redirection-order examples before combining destinations, because order can affect the result. Keep that as a later experiment rather than changing several variables at once. Mango Engineers’ Linux path includes shell foundations; ask about the current practical sequence and prerequisites.