Flowcharts for the Bash Startup Scripts


Chris Kassopulo  ckasso@sprynet.com January 2002

Introduction

Bash is the default command interpreter for linux. By reading, interpreting and executing commands from the keyboard it provides the buffer between you and the kernel. Bash is also a programming language. Programs called scripts can be submitted and executed. System and builtin commands are available.

Sourcing

Running a script is called sourcing and can be done manually with the commands sh scriptname or source scriptname. sh is a link to the default shell, bash. source is a bash builtin command (see Bash Reference Manual ). If #!/bin/sh is the first line of the script it can be started with the name of the script. When bash is started (depending on how it is started) it sources certain files. These scripts are the bash startup files and the commands in these scripts define or modify your environment.

Interactive Shells

The formal definition an interactive shell is "an interactive shell is one whose input and output are both connected to terminals or one started with the -i option" (see man bash). It looks for input from the terminal and delivers its output there. When you first login to your system bash is started as an interactive login shell. When you fire up a terminal window in X that is also an interactive shell but it is not a login shell. A different set of startup scripts is used for each.

Non-Interactive Shells

When you source a script from a terminal a non-interactive instance of the shell is launched that the script is executed from. A program might open a terminal window non-interactively and send output to it as it runs.

The Charts

For size and clarity there are two flowcharts for the bash startup scripts. They are split by login and non-login shells.

Login Flowchart
Non-Login Flowchart

With that said, be aware that there are many command line options to starting bash. There are for example, options to ignore or substitute certain startup scripts. Bash is very flexible. Also be aware that the charts presented here are not exhaustive. They don't cover all the options or combinations of options that could be used. There is some artistic license involved. But, if you are interested in the more obscure options, you probably don't need to look at these charts anyway.

Should you, or rather when you, notice an important omission or error please email me. Constructive suggestions and contributions are welcome.

The flow charts were initially drawn and laid out with Dia. The drawings were done and exported to Postscript with Sketch, then imported and saved as pngfiles with ImageMagick. The webpages were created with Bluefish.

searchSearch Index