About the Unix Shell
One very important utility is the shell.
Shell - user interface to the system, lets you communicate with a UNIX computer via the keyboard.
The shell interfaces you with the computer through three channels: standard input (STDIN), standard output (STDOUT), and standard error (STDERR). STDERR is the channel used for communicating program errors. We'll focus on STDIN and STDOUT.
STDIN is the channel, or stream, from which a program reads your input. When you type in your terminal, you're typing into the STDIN.
STDOUT is the channel, or stream, from which a program outputs data. When you run echo 'Hello, World!'
, the shell is printing the output into STDOUT. In this case, STDOUT is the terminal screen.
STDIN and STDOUT are the ways that you and the shell communicate. But what is the shell doing when you tell it to run a command?
Process of Running a Shell Command
Let's say I want to run the echo
command, as we did above. We type echo
in the terminal, then press Enter
. What the shell does is read the PATH
environment variable, which is a system variable that lists the different paths that programs are stored in.
Using printenv
to print the PATH
environment variable. Notice how many paths in this environment variable are ones dictated by the FHS:
Then, it will go through these paths and look for the program you are trying to run. For example, the echo
command is stored in /usr/bin
, a directory we can see in the PATH
environment variable:
Using which
to find the location of a program:
Once it finds it, it will run the program in a new process, wait for the program to give an exit status, then print any output of the program into STDOUT, in this case our terminal screen. Now, the shell is ready to run another command.
SSH
The shell is used to interface with a UNIX computer, but we're not going to go to the server room, plug in a keyboard, and start typing commands for our shell. We're going to use the Secure Shell (SSH) to remotely connect to Luria.
SSH is a program that lets you open a remote shell to your UNIX system. It's secure because your connection to the system is kept encrypted. For instructions on using SSH to connect to Luria, refer to the page below:
Last updated