Seattle Linuxchix Logo
History of Seattle LinuxChix Join us Events LiveJournal
Tutorials Our Members Articles Links

Using Unix/Linux Systems - What is Bash?

Elizabeth (Betsy) Aoki

What is the bash command? It is the Unix/Linux command that fires up the Bourne Again Shell ("bash") for the user, allowing them to input text commands that are interpreted by the shell for the operating system to execute.

Invoking the bash shell isn't normally necessary during the course of using a Red Hat version of Linux, simply because it is the default "shell" or interface with the OS, that comes with install. Nevertheless, system administrators, Unix junkies and experimental types may have installed other shells on their system such as sh (the classic Bourne shell), csh (the "C" shell) or tclsh (the Tcl language shell), and as such may need to fire up a different shell as programming need takes them.

Typing the word bash after the command prompt allows the user to enter a whole world of things to do. The best metaphor I've come up with to think about operating within the parameters of the bash shell once the shell has been started is the metaphor of a diving bell or bathysphere. Once a person enters the bathysphere of the shell, he or she is protected from the raw operating system, can interact with an ocean of fauna (shells scripts and functions) and flora (environmental variables, personal settings for how you want your shell script and its editor-modes to behave). Using bash means engaging with a specifically-engineered apparatus designed to interact with the denizens of the deep waters of the operating system in specified ways. The rest of this essay will give an overview of the bash shell's special features and considerations.

The bash shell, creating by Brian Fox in 1988, represents an amalgam of features from the original Bourne shell, Korn and C shells. When it fires up as a login shell for the user, the bash shell reads the systemwide startup file at /etc/profile or ones the user has set up at ~/.bash_profile or ~/.bash_login or ~/.profile. These files contain instructions for how the shell will be implemented -- what text editor is the default editor as the user types, where the shell's executable file is, and other information pertaining to shell functionality such as the values of shell variables.

Bash sell variables come in all shapes and sizes. One of the more basic is prompting variable, or the string that is used as the shell prompt - bash has 4 prompting variables.

  • PS1, that describe what a user sees as a default prompt ("$Betsy:")
  • PS2, what the shell tells you if you forget to finish a command (usually it says ">" and waits for you to do something)
  • PS3 a prompt related to the select command that wants you to pick a number from a list of values
  • And PS4, a variable often used for debugging things that go wrong in the shell or shell scripts

Other variables include environmental variables, which allow the user to customize the shell and report what's going on within the shell. These variables are also automatically accessible to shell programs, or scripts, that can be called by the user or by shell commands. As with the controls of a bathysphere, the environmental variables give the user certain specific ways in which he or she can interact with the operating system environment and to a certain extent, control the shell's activities.

Unix is frankly an anal operating system, sort of like a file clerk who continually wants to know what's going on with the things he put in their certain special places at pre-set times. Thus the bash shell has environmental variables such as HOME, that contains the value of the user's home directory, BASH, which tells you where bash is located in the system, PATH, which is where the shell looks every time you enter a command (multiple locations are separated by colons, MAILPATH, which is all the files that the shell checks to see if they have changed (ie, you have mail), or SHELL (which holds the name of your login shell - which may or may not be bash, depending on how you've got it set).

If you have other variables that you want made available to your shell scripts, you need to set them down in the file that is invoked every time you type the word bash (.bashrc) as well as the file that kicks in when you login to the shell(.bash_profile). This is also the place to have the shell call custom shell scripts you've created that establish your own custom commands that you want to use while in the shell, or special nicknames you want to automatically use to call standard shell commands rather than using the alias command in each instance of the shell.

The user can also control overall shell behavior by changing a shell's options. The bash shell comes with roughly 20 options, the nature of which can be set using the set command. These include things like, which editor is the default (emacs editing mode is used by bash as a default, but you can set it to vi) and not allowing redirection of output to overwrite an existing file ("noclobber"). In bash 2.0, the shopt built-in allows you to adjust your shell's options, some of which are quite different from the options covered in the earlier bash versions' set command (for example, you can set bash to note that you read your mail should you have accessed it after the mailfile was last checked).

The .bash_logout file is the (optional) file read by the shell upon the user exiting the bash shell. The bash user can edit this file such that the shell will close up shop in the way that the user wants: delete temporary files, log the amount of time you've spent in the system, count all the new files created or anything else that might be in their scripting work.

System administrators can also do things with the bash shell on a global level to influence what users can do when they invoke bash on the local level. Or only allow users to have restricted capabilities -- including their ability to change directories or redirect outputs to files. When you invoke the bash command as a regular user, you may not be able to do the same complement of things on the system as you would if you were root.

There is an abundance of other topics under the heading of bash shell- how to compose/organize a shell script, what the built-in commands are, what kind of syntax you use in your shell commands and scripts. This essay is merely an overview of the general characteristics of the bash shell and what the bash command actually does when invoked. Like the bathysphere, the bash shell command is a means for getting the user to interact with the depths of the Linux operating system that, while not unfathomable, is certainly less easily managed without the protective constructs of a command interpreter.