Using bash

From Juneday education
Jump to: navigation, search

bash is a shell executing in a terminal. You need to have a terminal capable of running bash. We provide information on how to install and start such a terminal and bash for some of the existing operating below:

Install Bash

Windows

We strongly suggest you use cygwin to get a working terminal and a bash installation. Windows 10 comes with a version of bash you can enable but this version does not work properly with our course material. Using bash from other installations, such as from git, is not recommended. Cygwin comes in two version, one for 32-bit and one for 64-bit computers. If you have a rather modern computer chances are high it is a 64 bit computer.

Note: You need to install additional packages. You can do this now or after the installation, we suggest now. See below for a list of the additional packages

Installation manuals

Installing and Updating Cygwin Packages - instructions from the source

HOWTO install Cygwin - graphical installation guide

Videos

Here are some videos showing you how to install cygwin:

GNU/Linux

GNU/Linux comes with several terminals and bash installed, so no need to install anything.

MacOS

MacOS comes with a terminal and bash installed, so no need to install anything.

Install additional software

Windows

Cygwin not only comes with a terminal and bash. You also get a lot of shell tools, some of which are covered in these books in shell tools. But with cygwin you can install lots of (yes, LOTS OF!), different software.

In order to add stuff to the Cygwin installation in Windows, you simply start the installation program again (often a file called Setup(X86_64).exe with the Cygwin logo for icon). Therefore, you should keep the installation program when you first install Cygwin, so that you easily can add packages to it when you discover you need another program/command or package later on.

We will show you how you install a small command line calculator, bc in the video below.

Here are some pointers for what to install. You can install all the packages below regardless of what book you are following, if you want to learn more about the commands and tools below. The lists below are hints about what commands are needed in the exercises etc from the various books on this wiki.

Install the following extra cygwin packages:

  • curl
  • unzip
  • wget

Videos

GNU/Linux

No extra packages needed.

MacOS

MacOS is missing a couple of programs we're using in our courses/books. You can get around this by installing either Homebrew or The MacPorts Project. Both of them require that xcode is installed.

Read the following page Homebrew and MacPorts for more information. Once installed you might want to read to Quick guide to using Homebrew and MacPorts

Course specific software

Some of our courses need additional packages. Check the pages on setting up your environment for these course matierals:

Running

Windows

  • launch Cygwin64 Terminal (see Desktop menu item)

GNU/Linux

You can do either of the following:

  • press ctrl-alt-t
  • press windows key and when text are appears, type "terminal"

MacOS

Open the terminal by opening your Applications folder. Next, open the Utilities folder. Next, open the Terminal application. Could add this to your dock. Alternatively, use "Spotlight search" in OS X, searching for “terminal”.


Verify bash

Start a terminal and bash

Windows

  • launch Cygwin64 Terminal (see Desktop menu item)

GNU/Linux

You can do either of the following:

  • press ctrl-alt-t
  • press windows key and when text are appears, type "terminal"

MacOS

Open the terminal by opening your Applications folder. Next, open the Utilities folder. Next, open the Terminal application. Could add this to your dock. Alternatively, use "Spotlight search" in OS X, searching for “terminal”.

Verify bash

You can easily verify that it is bash running in the terminal by typing the following command in the terminal window:

echo $0 and then press the Enter key.

You should now see bash printed in the terminal.

Type pwd and you should see the following:

Windows/Cygwin terminal:

/home/<your username>/

Mac OS Terminal:

/Users/<your username>

Type the following command in your terminal: mkdir textfiles

Type the following command in your terminal: ls

You should see at least a directory called textfiles in the output from ls

Type the following command next: file textfiles and the conversation between you and bash should look like this:

$ file textfiles/
textfiles/: directory

The highlighted line is the response from the file command. file is a neat program to investigate the type of files in your file system. The textfiles file is a so called directory (sometimes called folder).

Getting started with the terminal and bash

Description

Making sure you have a terminal capable of (and currently running) bash.

Videos

  • Navigate through directories using ls, cd and pwd and create and remove directories and files using mkdir, rmdir and rm (eng)

Bash version

If you want to check what bash, in case you have many bash versions installed, is started when you type bash you can use the command which:

$ bash
/usr/bin/bash

This means that when you type bash the bash found in /usr/bin/bash is started.

If you would like to find where bash can be found in your PATH, you can use the following:

$ for path in $(echo $PATH | sed 's,:, ,g'); do printf "Checking %20s : " $path ; if [ -f $path/bash ] ; then echo $path/bash; else  echo "-" ; fi ; done
Checking            /usr/bin/ : /usr/bin//bash
Checking      /usr/local/bin/ : -
Checking      /opt/local/bin/ : -
Checking       /home/hesa/bin : -

If you would like to see the version of the bash you're currently running you can type:

$ echo $BASH_VERSION
4.4.12(1)-release