We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

Standard Error

Standard Error, usually called stderr, is a data stream just like standard output, but is intended to be used for error messages.

It's a separate stream so that you can redirect it to a different place if need be, but by default, it prints to your terminal just like stdout.

Redirecting Streams

You can redirect stdout and stderr to different places using the > and 2> operators. > redirects stdout, and 2> redirects stderr.

Redirect stdout to a File

echo "Hello world" > hello.txt
cat hello.txt
# Hello world

Redirect stderr to a File

cat doesnotexist.txt 2> error.txt
cat error.txt
# cat: doesnotexist.txt: No such file or directory

In this example, cat is used to intentionally generate an error message (since the file doesn't exist), which is then redirected to error.txt.

Assignment

There's a worldbanc/private/bin/process_transactions.sh script that:

  • Accepts a path to a CSV file containing transactions data as a positional argument (or CLI argument).
  • Prints modern transactions (after the year 2000) to stdout, and old transactions (before 2000) to stderr.

Submit the shell checks.

The temporary directory (/tmp) exists by default on all Unix-like systems, in your root directory. Files there are deleted by your system routinely. It's a great place to store temporary files that you don't need to keep around.

Tip

SCRIPT_PATH PATH_TO_CSV 2> /tmp/worldbanc.log