Introduction
What are Unix shells?
Do I need to use them?
Which one should I use?
This section answers these questions and covers how we are going to run a shell for this course.
Unix shells
Unix shells are command line interpreters for Unix-like operating systems1: the user enters commands as text—interactively in a terminal or in scripts—and the shell passes them to the operating system.
It is thus a way to give instructions to the machine through text instead of using a graphical user interface (GUI).
Types of Unix shells
Bash, the Bourne Again SHell, released in 1989 as part of the GNU Project, is the default Unix shell on most systems, including the Alliance clusters. The executable to use it is bash
. It replaces the initial Bourne shell—executable: sh
. We will mostly learn Bash in this course.
A newer and very popular shell, almost fully backward compatible with Bash and extending its capabilities, is Z shell (or Zsh)—executable: zsh
. macOS recently changed its default shell from Bash to Zsh. We will talk about it at the end of this course.
Both Bash and Zsh are POSIX compliant, meaning that they respect the Portable Operating System Interface standards, making them compatible between operating systems.
There are several other Unix shells, some of which are also POSIX compliant and with a very similar syntax such as KornShell (ksh), others with a more different syntax and not POSIX compliant such as fish or C shell (csh).
Why use a shell?
While automating GUI operations is really difficult, it is easy to rerun a script (a file with a number of commands). It is also very easy to apply the same command to any number of files. Unix shells thus allow the creation of reproducible workflows and the automation of repetitive tasks.
Imagine you had 1000 files in a directory and you wanted to rename them all.
Using Windows Explorer or macOS Finder, you could right click on every file one by one to rename it, but it would take hours. Using a Unix shell, this is done by a very simple command and takes an instant.
Shells are particularly powerful to launch tools, modify files, search text, or combine commands.
Because shells are powerful, you can easily make consequential mistakes (e.g. deleting a lot of files). For this reason, it is a good idea to make backups of your data before you start experimenting with novel shell commands (it is a very good idea to make frequent backups of your data anyway!).
Finally, shells allow to access remote machines and HPC clusters.
Running Bash
Since Bash is a Unix shell, you need a Unix or Unix-like operating system. This means that people on Linux or macOS can use Bash directly on their machine.
For Windows users, there are various options:
- using Windows Subsystem for Linux (WSL),
- using a Bash emulator (e.g. Git BASH), but those only have a subset of the usual Bash utilities,
- using a Unix-like environment for Windows (e.g. Cygwin),
- using a Unix Virtual machine,
- accessing a remote Unix machine.
How we will use Bash today
Today, we will connect to a remote HPC cluster (supercomputer) via SSH (secure shell). HPC systems always run Linux.
Those on Linux or macOS can use Bash directly on their machine if they prefer, but using our remote system will give you an opportunity to practice using SSH—something you will have to do if you ever want to use the Alliance supercomputers.
On macOS, the default is now Zsh (you can see that by launching the application called “Terminal” and typing echo $SHELL
followed by the <enter>
key), but Zsh is almost fully compatible with Bash commands, so it is fine to use it instead. If you really want to use Bash, simply launch it by typing in “Terminal”: bash
, then pressing the <enter>
key.
Remote connection via SSH
Step one: get a username and the password
We will give you a link to an etherpad during the workshop. Add your name next to a free username to claim it.
We will also give you the password for our training cluster.
Step two: run the ssh command
• Linux and macOS users
Linux users: open the terminal emulator of your choice.
macOS users: open “Terminal”.
Then type:
ssh userxx@hostname
- Replace
userxx
by your username (e.g.user09
) - Replace
hostname
by the hostname we will give you the day of the workshop.
• Windows users
We suggest using the free version of MobaXterm. MobaXterm comes with a terminal emulator and a GUI interface for SSH sessions.
Open MobaXterm, click on “Session”, then “SSH”, and fill in the Remote host name and your username.
Here is a live demo.
Step three: enter the password
When prompted, enter the password we gave you.
You will not see any character as you type the password: this is called blind typing and is a Linux safety feature. It can be unsettling at first not to get any feed-back while typing as it really looks like it is not working. Type slowly and make sure not to make typos.
Footnotes
Unix-like systems include Linux, macOS, and a few others.↩︎