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.
Note that this cluster is virtual and temporary. It will only be available for the duration of this course.
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
, then pressing Enter
), 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 Enter
.
Remote connection to the cluster
Step 1: get the info
During the workshop, we will give you 3 pieces of information:
- a link to a list of usernames,
- the hostname for our temporary training cluster,
- the password to access that cluster.
Step 2: claim a username
Add your first name or a pseudo next to a free username on the list to claim it.
Your username is the name that was already on the list, NOT what you wrote next to it (which doesn’t matter at all and only serves at signalling that this username is now taken).
Your username will look like userxx
—xx
being 2 digits—with no space and no capital letter.
Step 3: 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
and press Enter
.
- Replace
userxx
by your username (e.g.user09
). - Replace
hostname
by the hostname we will give you the day of the workshop.
When asked:
Are you sure you want to continue connecting (yes/no/[fingerprint])?
Answer: “yes”.
• Windows users
We suggest using the free version of MobaXterm. MobaXterm comes with a terminal emulator and a GUI interface for SSH sessions.
Here is how to log in with MobaXterm:
- open MobaXterm,
- click on Session (top left corner),
- click on SSH (top left corner),
- fill in the Remote host * box with the cluster hostname we gave you,
- tick the box Specify username,
- fill in the box with the username you selected (e.g.
user09
), - press OK,
- when asked
Are you sure you want to continue connecting (yes/no/[fingerprint])?
, answer: “yes”.
Here is a live demo.
Step 4: enter the password
When prompted, enter the password we gave you.
You will not see anything happen as you type the password. This is normal and it is working, so keep on typing 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.
Then press Enter
.
You are now logged in and your prompt should look like the following (with your actual username):
[userxx@login1 ~]$
Troubleshooting
Problems logging in are almost always due to typos. If you cannot log in, retry slowly, entering your password carefully.
Footnotes
Unix-like systems include Linux, macOS, and a few others.↩︎