Jump to content

Bash Shell Scripting/Prerequisites

From Wikibooks, open books for an open world

You will need to have Bash installed on your system, or need to be able to connect remotely to a Unix/Linux system where you have shell access, such as a university computing center or a public-access system like SDF.org. Instructions for accessing another system remotely (e.g., over SSH) are beyond the scope of this guide.

A GNU/Linux operating system like Ubuntu, Manjaro, Mint, and so on will typically have Bash installed by default and set to be the login shell. If you are not already using a Linux distribution, you should be able to install one onto an old laptop or a virtual machine without much trouble.

Docker or other container runtime

[edit | edit source]

If you are already familiar with Docker or a similar container runtime environment, you can pull the bash container image from Docker Hub; this is a very small (~15 MB) image that will allow you get started quickly. For example, this command

docker run --rm -it -v .:/homework bash

will make the contents of the current directory available as /homework inside the container, allowing you to save your work between invocations of the container runtime as you go through this guide. Some external programs referred to in the guide may not be installed by default; however, this container uses Alpine Linux under the hood, so you can refer to that project's help for how to install whatever is needed.

macOS and other *nix systems

[edit | edit source]

If you are using another operating system in the Unix family, like FreeBSD or macOS, Bash is not as likely to be the default shell. If the system administrator allows it (or if you are the system administrator), you can change your default shell with chsh; see man chsh for details. If /bin/bash is not available as a choice, you may be still able to install Bash from the system's package manager, or a third-party repository in the case of macOS; see here for details.

Windows

[edit | edit source]

If you are on a Windows 10 or Windows 11 system, you can install Windows Subsystem for Linux. This will give you a full-featured GNU/Linux system with a dedicated terminal, and the ability to access your other files from within the Linux environment. This option is comparable, in terms of disk utilization and functionality, to installing a Linux distribution into a virtual machine; there is no clear benefit of one over the other for the purposes of doing the exercises in this book.

Cygwin or Git for Windows are other fine options, which you may already have installed. Both default to the Bash shell, include a full-featured terminal application, and come with many useful Unix utilities besides, some of which are referred to in this guide.

Mobile devices

[edit | edit source]

On Android, an app called Termux can be installed, which provides the Bash shell as an option. For iOS, you may be interested in iSH, although the bash package must be installed as a separate step.