LinuxCommandLibrary
GitHubF-DroidGoogle Play Store

bash

Unix shell and command language interpreter

TLDR

Run script
$ bash [script.sh]
copy
Execute command
$ bash -c ["echo hello"]
copy
Interactive login shell
$ bash -l
copy
Read from stdin
$ echo "ls -la" | bash
copy
Debug script
$ bash -x [script.sh]
copy
Check syntax only
$ bash -n [script.sh]
copy

SYNOPSIS

bash [options] [file] [arguments]

DESCRIPTION

bash (Bourne Again SHell) is a Unix shell and command language interpreter. It's the default shell on most Linux distributions and macOS, providing command execution, scripting, job control, and extensive programming features.Bash is backward-compatible with the original Bourne shell (sh) while adding numerous improvements and modern features.

PARAMETERS

-c string

Execute command from string
-l, --login
Login shell (sources profile files)
-i
Interactive mode
-x
Print commands before execution (debug mode)
-n
Syntax check only (no execution)
-e
Exit on first error
-u
Error on undefined variables
-v
Verbose mode (print input lines)
--noprofile
Don't read profile files
--norc
Don't read ~/.bashrc
--posix
Behave according to POSIX standard
-r, --restricted
Start a restricted shell
--version
Display bash version

CONFIGURATION

~/.bashrc

Per-user configuration for interactive non-login shells. Aliases, functions, prompt customization.
~/.bash_profile
Per-user configuration for login shells. Typically sources ~/.bashrc.
~/.bash_logout
Executed when a login shell exits.
/etc/bash.bashrc
System-wide configuration for interactive shells.
/etc/profile
System-wide configuration for login shells.

FEATURES

- Command history (readline)- Tab completion- Job control (fg, bg, jobs)- Arithmetic evaluation- Arrays and associative arrays- Functions- Pattern matching and globbing- Process substitution- Here documents- Conditional execution- Loops and flow control

STARTUP FILES

Login shell

/etc/profile, ~/.bashprofile, ~/.bashlogin, ~/.profile
Interactive non-login
~/.bashrc
Non-interactive
$BASH_ENV

SPECIAL VARIABLES

$0 - Script name$1, $2, ... - Positional parameters$@ - All parameters$# - Parameter count$? - Exit status of last command$$ - Process ID$! - PID of last background job

INSTALL

sudo apt install bash
copy
sudo dnf install bash
copy
sudo pacman -S bash
copy
sudo apk add bash
copy
sudo zypper install bash
copy
brew install bash
copy
nix profile install nixpkgs#bash
copy

CAVEATS

Bash-specific features not portable to POSIX sh. Scripts should use `#!/bin/bash` not `#!/bin/sh`. Unquoted variables can cause word splitting. Use `shellcheck` to validate scripts.

HISTORY

Bash was created by Brian Fox for the GNU Project in 1989 as a free replacement for the Bourne shell, first released as version 0.99. Version 5.0 was released in 2019.

SEE ALSO

sh(1), zsh(1), shellcheck(1)

Braincup
Open source brain training for math, memory and focus
Braincup mini-games
41 mini-games · Apache-2.0
No ads · No tracking
Play in browser
Download Braincup on the App StoreGet Braincup on Google PlayGet Braincup on F-Droid
276 stars
From the maker of Linux Command Library
Copied to clipboard
Braincup
Open source brain training for math, memory and focus. 41 mini-games, from mental arithmetic to Sudoku, N-Back and Solo Chess.
Apache-2.0 licensed · No ads · No tracking · No account
From the maker of Linux Command Library
Download Braincup on the App StoreGet Braincup on Google PlayGet Braincup on F-Droid