# 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.

```bash
[asoberan@luria net]$ echo 'Hello, World!'
Hello, World!
```

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:*

<pre class="language-bash"><code class="lang-bash"><strong>[asoberan@luria net]$ printenv PATH
</strong>/home/asoberan/.conda/envs/class/bin:/home/software/conda/miniconda3/condabin:/home/software/conda/miniconda3/bin:/home/asoberan/.local/bin:/opt/ohpc/pub/mpi/mvapich2-gnu/2.2/bin:/opt/ohpc/pub/compiler/gcc/5.4.0/bin:/opt/ohpc/pub/prun/1.1:/opt/ohpc/pub/autotools/bin:/opt/ohpc/pub/bin:/home/asoberan/.local/bin:/home/software/google-cloud-sdk/google-cloud-sdk-193.0.0/google-cloud-sdk/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin
</code></pre>

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:*

```bash
[asoberan@luria net]$ which echo
/usr/bin/echo
```

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:

[#accessing-luria](https://igb.mit.edu/computing-resources/luria-cluster#accessing-luria "mention")


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://igb.mit.edu/mini-courses/introduction-to-unix/the-unix-shell/about-the-unix-shell.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
