This content is from the fall 2016 version of this course. Please go here for the most recent version.

What is the Shell?

The shell (or bash or terminal) is a program on your computer whose job is to run other programs, rather than do calculations itself. The shell is a very old program and in a time before the mouse it was the only way to interact with a computer. It is still extremely popular among programmers because it is very powerful, fast, and is particularly powerful at automating repetitive tasks.

Here we use the shell for a more modest goal: To navigate the file system, confirm the present working directory, and cement the git to GitHub connection.

Starting the shell

In RStudio, go to Tools > Shell. This should take you to the shell (on Mac: Terminal, on Windows: GitBash or equivalent). It should be a simple blinking cursor, waiting for input and looks similar to this (white text on black background, or black text on white background):

Using the shell

The most basic commands are listed below:

A note for Windows users

On Windows, the program that runs the shell is called Command Prompt or cmd.exe. It looks like this:

Unfortunately, the default Windows shell does not support all the commands that other operating systems do. This is where GitBash comes in handy: it installs a light version of a shell that does support all the above commands. When you access the shell through RStudio, RStudio actually tries to open GitBash if it can find it, but it will open the default Windows Command Prompt if GitBash is not found.

If you get an error message such as `pwd is not recognized as an internal or external command, operable program or batch file.` from any of the previous commands, that means that RStudio could not find GitBash. The most likely cause of this is that you did not install git using the recommended method so try re-installing git.

If you followed the installation instructions and still cannot run GitBash, you should find it under the Start Menu > Git > Git Bash. If you’re still confused, go back and watch the first three minutes of this video tutorial on installing Git for Windows.

Acknowledgments

This work is licensed under the CC BY-NC 4.0 Creative Commons License.