Bash – Does the shell have the same standard input, standard output, standard error like each other command

bashinputshell

The bash, for instance, is located under /bin/bash, this means it is a command and each command has the three (0,1,2) pores: standard input, standard output, standard error.

Is this also 100 percent true for the shell or is there something different since the special meaning of the shell as a command or process?

Best Answer

It's the same as any other program. This allows you to redirect and pipe the I/O like other programs.

echo "cat filename" | bash

will execute the cat filename command when bash reads its standard input from the pipe.

bash -c "echo foo" > filename

will execute the echo foo command, and the output will be redirected to the file.

On Unix, there's nothing "special" about the shell. It's just an ordinary program whose primary purpose is executing other programs.