When you open a terminal on most Linux distributions, the command-line interpreter you’re using is called Bash, which stands for Bourne Again SHell. It’s the default user shell on virtually every major Linux distribution, including Ubuntu, Debian, Fedora, and Arch Linux. You can check your own default shell with echo $SHELL — on a standard system, it will return /bin/bash.
What Exactly Is a Shell?
A shell is a program that lets you interact with the operating system by typing commands. It reads your input, interprets it, and tells the kernel what to do. The shell also provides scripting capabilities — you can write sequences of commands in a file and execute them as a program. Every Linux user has a default shell assigned to their account, which is what runs when they open a terminal or log in via SSH.
Bash is not the only shell available. Others include Zsh, Fish, Ksh, and Sh. Each has its own syntax, features, and quirks. But Bash is the one you get out of the box on most systems, and it’s the one that’s most compatible with the POSIX standard that defines how Unix-like shells should behave.
Where Did Bash Come From?
Bash was created in 1989 by Brian Fox as a free replacement for the Bourne shell (sh), which was the original Unix shell written by Stephen Bourne at AT&T Bell Labs. The name “Bourne Again SHell” is a pun on “born again” and the Bourne shell. It was developed for the GNU Project, which aimed to create a free Unix-like operating system. Bash became the standard shell for GNU/Linux and is also the default shell on macOS (though macOS uses an older version) and on Windows through the Windows Subsystem for Linux.
Because Bash is open source and part of the GNU toolset, it’s available on virtually every Linux distribution. Its widespread adoption means that if you write a shell script in Bash, it will run on almost any Linux machine without modification — a key reason for its continued dominance.
How Bash Works: Interactive and Scripting Modes
Bash operates in two main ways:
- Interactive mode: You type a command, press Enter, and Bash executes it. It shows a prompt (often ending with
$for normal users or#for root) and waits for your next input. - Scripting mode: You put a series of commands in a text file, make it executable with
chmod +x script.sh, and run it. The first line of a script usually is#!/bin/bash— this tells the system which interpreter to use.
Bash also reads configuration files when it starts. For interactive login shells, it reads /etc/profile and ~/.bash_profile. For non-login interactive shells, it reads ~/.bashrc. These files let you set environment variables, aliases, and functions that customize your shell experience.
How to Check and Change Your Default Shell
To see which shell you’re currently using, type:
echo $SHELL
This shows the login shell for your user. To see a list of all installed shells, use:
cat /etc/shells
If you want to change your default shell to another one (say, Zsh), use the chsh command:
chsh -s /usr/bin/zsh
You’ll need to log out and back in for the change to take effect. The new shell will be used for all future terminal sessions.
Common Problems and Misconceptions
One common mistake is confusing the default shell with the shell used for a specific script. Even if your default shell is Bash, a script that starts with #!/bin/sh will run under the Bourne shell (or a POSIX-compatible shell like Dash on Debian-based systems). This can cause subtle differences in behavior, especially with features like arrays or [[ ]] conditionals that are not POSIX-compliant.
Another misconception is that Bash is the only shell you need. While it’s true that Bash is powerful, other shells offer advantages. Zsh has better tab-completion and spelling correction, Fish has a more user-friendly syntax, and Ksh is faster in some benchmarks. But for portability and ubiquity, Bash is the safest choice.
Bash vs. Other Shells: A Quick Comparison
Here’s how Bash stacks up against the most common alternatives:
- Bash: Default on most Linux distros, POSIX-compliant, huge community, supports arrays and advanced scripting.
- Zsh: Default on macOS since Catalina, highly customizable, excellent completion, mostly Bash-compatible.
- Fish: “Friendly interactive shell”, great for beginners, but not POSIX-compliant — scripts written for Bash won’t run without changes.
- Ksh: KornShell, older but fast, used in some enterprise environments, POSIX-compliant.
- Dash: A lightweight POSIX shell, used as
/bin/shon Debian-based systems for faster boot times, but missing many interactive features.
For most users, sticking with Bash is the right call. It’s the most portable, best documented, and what you’ll find on almost any server you SSH into.
Is Bash Safe to Use?
Bash itself is safe — it’s a mature, widely used program. However, there have been security vulnerabilities in the past, the most famous being Shellshock (CVE-2014-6271), which allowed attackers to execute arbitrary commands via specially crafted environment variables. That vulnerability was patched in 2014, but it highlighted the importance of keeping your system updated.
When writing Bash scripts, be careful with user input. Always quote variables to prevent word splitting, and avoid using eval unless you absolutely know what you’re doing. These practices reduce the risk of command injection.
Frequently Asked Questions
Is Bash the same as the terminal?
No. The terminal is the window that displays text and accepts input — it could be a physical monitor or an app like GNOME Terminal. Bash is the program running inside that terminal that interprets your commands. You can run different shells inside the same terminal.
Can I use Bash on Windows?
Yes. Windows Subsystem for Linux (WSL) allows you to run a full Linux environment, including Bash, on Windows. You can also install Git Bash, which provides a Bash-like environment for Git commands, but it’s not a full Linux shell.
Why does my script work in the terminal but not when I run it as a script?
This usually happens because the script’s shebang line points to a different shell, or because the script doesn’t have execute permissions. Check the first line of the script and run chmod +x script.sh. Also, ensure the script uses #!/bin/bash if it relies on Bash-specific features.
What does #!/bin/bash mean?
It’s called a shebang. When you run a script, the kernel reads this line and uses the specified program (/bin/bash) to interpret the rest of the file. If you omit it, the system will use your default shell, which might not be Bash.
How do I make Bash my default shell?
Most Linux installers set Bash as the default. If you changed it and want to revert, run chsh -s /bin/bash and restart your session. You can verify with echo $SHELL.
Is Bash the same as sh?
No. sh is the Bourne shell, the original. Bash is a superset of sh — it includes all sh features plus many extensions. On many systems, /bin/sh is actually symlinked to a lighter shell like Dash for performance, so scripts that run under sh may behave differently than under Bash.
Related
General steps for current mainstream versions; menus can differ by device and version. See the disclaimer or report an error.
More in this bed
- Fix Payday 2 Crash Issues on PC: A Step-by-Step Guide
- Remove a Remote Access Trojan from Windows PC
- Google Pixel & Pixel XL: How to Turn Off Snooze
- Facebook as AIM Messenger: Step-by-Step Guide
- iPhone 17 SOS Service Issue: How to Fix It
- Factory Reset HP Laptop Without Password: 2 Ways