bash
Start a new Bash shell
TLDR
Start an interactive shell session
Start an interactive shell session without loading startup configs
Execute specific [c]ommands
Execute a specific script
E[x]ecute a specific script, printing each command before executing it
Execute a specific script and stop at the first [e]rror
Execute specific commands from stdin
Start a [r]estricted shell session
SYNOPSIS
bash [options] [file]
PARAMETERS
-c string
Execute commands from string.
-i
Force interactive shell.
-l
Make bash act as if invoked as a login shell.
-r
Restricted shell. Disables certain commands and functionalities.
-s
Read commands from standard input.
--version
Display version information and exit.
--help
Display help message and exit.
DESCRIPTION
The bash command is a Unix shell and command language interpreter. It's a widely used shell on Linux systems and serves as the default login shell for many distributions. bash is an acronym for Bourne Again SHell, a successor to the original Bourne shell (sh).
It interprets and executes commands read from standard input (keyboard) or from a file (script). bash provides features like command-line editing, command history, job control, shell functions, and scripting capabilities. It supports variables, conditional statements, loops, and other programming constructs, making it a powerful tool for automating tasks. It performs filename globbing (wildcard expansion), command substitution, and process execution.
bash configuration can be customized through startup files like `.bashrc`, `.bash_profile`, and `.bash_login`. These files are executed when a user logs in or starts a new interactive shell. Environment variables play a crucial role in configuring the behavior of bash and other programs it runs. Error handling and signal management are also important aspects of bash scripting, allowing scripts to gracefully handle unexpected situations. It is an essential tool for Linux system administration and scripting.
CAVEATS
Complex scripts can become difficult to debug. Relying heavily on shell scripts for critical applications can make the system dependent on bash's specific behavior.
STARTUP FILES
bash reads and executes commands from various startup files depending on how it's invoked. Common startup files include `.bashrc`, `.bash_profile`, `.profile`, and `.bash_login`. The order and content of these files determine the shell's environment and behavior.
EXIT STATUS
bash, like all commands, returns an exit status. An exit status of 0 typically indicates success, while a non-zero exit status indicates failure. This value can be accessed using the `$?` variable and is crucial for error handling in scripts.
HISTORY
bash was created by Brian Fox as a free software replacement for the Bourne shell (sh). Development began in 1988, and it was first released in 1989. It quickly became the default shell for the GNU operating system and many Linux distributions. Over time, numerous features and improvements have been added, making it a highly versatile and widely used shell. It continues to be actively maintained and updated.