392-7 Bash shell confusion

I am on screen 7 of Standard Streams and File Descriptors, the command ls /dev/null /home/inexistent 2>&1 1>redirection_order, gives only one output.

Why? Can anybody answer?

Hey @MukulDas,

See below. Thanks.

Url Path to DQ Mission

I have edited the url to use absolute path instead of relative path in your original post. In the future, please use absolute url path instead. It helps with a faster response with a clickable mission link.

A relative url to the mission link to app.dataquest.io is un-clickable since this forum community.dataquest.io and app.dataquest.io contains in different domain.

Notes on rephrasing question

I understand your frustration on the confusion. However, we shouldn’t be demanding an answer.

Instead, rephrase your question into exactly what you are not sure about. For example: “I do not understand why the bash commands only gives one output.”

Basics on file descriptors

0 , 1 and 2 represent the standard file descriptors in POSIX operating systems. A file descriptor is a system reference to (basically) a file or socket.

The left side of 2>&1 tells you what will be redirected, and the right side tells you where to. The & is used on the right side to distinguish stdout (1) or stderr (2) from files named 1 or 2 . So, 2>1 would end up creating a new file (if it doesn’t exist already) named 1 and dump the stderr result in there.

DQ Bash command
ls /dev/null /home/inexistent

The command above list all files in directories /dev/null and /home/inexistent.

ls /dev/null /home/inexistent 2>&1 1>redirection_order

2&>1 redirects the stderr output to the stdout.
1>redirection_order redirects the stdout output to a filename redirection_order

First, stderr redirects to stdout.
Second, stdout redirects to a file.
We have stderr -> stdout -> file.
Hence, the output of the command is written to a file.

1 Like