Class 6 of 37 • Linux Shell Essentials \t\t\t\t

Bash Shell in Linux Programming

Introduction of Bash Shell

 Bash is a Unix shell and command language written by Brian Fox for the GNU Project as a free software replacement for the Bourne shell. First released in 1989, it has been distributed widely as it is a default shell on the major Linux distributions and OS X.

 Bash is a command processor that typically runs in a text window, where the user types commands that cause actions. Bash can also read commands from a file, called a script. Like all Unix shells, it supports filename globbing (wildcard matching), piping, here documents, command substitution, variables and control structures for condition-testing and iteration. The keywords, syntax and other basic features of the language were all copied from sh. Other features, e.g., history, were copied from csh and ksh. Bash is a POSIX shell, but with a number of extensions.

 The shell's name is an acronym for Bourne-again shell, punning on the name of the Bourne shell that it replaces and on the term "born again" that denotes spiritual rebirth in contemporary American Christianity.

Example


# Checking if days exceed a year
days=400
if [ "$days" -gt 365 ]; then
   echo "This is over a year."
fi
							

Feature of Bash Shell

      Alias for used commands

      History mechanism.

      Pattern Matching for filename.

      Interactive editing facility using editor.

      Home directory can be represented by a tilde sign (~).


Essential Bash Keyboard Shortcuts (GNU Readline)

Efficiency in the Linux terminal comes from mastering GNU Readline keybindings:

Shortcut Action Performed
Ctrl + A Jump cursor to the beginning of the line.
Ctrl + E Jump cursor to the end of the line.
Ctrl + U Cut/erase from current cursor position back to start of line.
Ctrl + K Cut/erase from current cursor position forward to end of line.
Ctrl + R Reverse incremental history search (type keyword to find past commands).
Ctrl + L Clear the terminal screen (equivalent to typing clear).
Tab Auto-complete command names, file paths, and options.

Bash Configuration Files: .bashrc and .bash_profile

When you customize your prompt, export environment variables, or create permanent aliases, you store them in Bash initialization scripts:

     ~/.bashrc: Loaded every time an interactive non-login shell starts (e.g. opening a new terminal window in Ubuntu).

     ~/.bash_profile: Loaded once upon initial system login (via SSH or text console).


# Example: Adding custom aliases to ~/.bashrc
$ cat >> ~/.bashrc << 'EOF'
alias ll='ls -la --color=auto'
alias update='sudo apt update && sudo apt upgrade -y'
export EDITOR=vi
EOF

# Reload changes immediately without logging out
$ source ~/.bashrc
							

Frequently Asked Questions (FAQ)

Run bash --version or check the internal shell variable echo $BASH_VERSION. Modern Linux systems typically run Bash version 5.x.

Command substitution runs a command in a subshell and replaces the command with its standard output text. Modern syntax uses $(command) (e.g., today=$(date +%Y-%m-%d)), which allows nesting, replacing the older backtick syntax `command`.

Next Step in Your Linux Learning Path:

Transition to terminal text editing and learn modal philosophy in Class 7: Overview of VI Editor.

Continue to Class 7: Overview of VI Editor → Previous: ← Korn Shell | Full Syllabus

Share Share on Facebook Share on Twitter Share on LinkedIn Pin on Pinterest Share on Stumbleupon Share on Tumblr Share on Reddit Share on Diggit

You may also like this!