📘 History & Purpose of Bash
🎯 What You Will Learn
- Understand what Bash is and how it evolved from earlier Unix shells.
- Learn the design purpose and major problems Bash was built to solve.
- Recognize Bash’s dual nature as a command interpreter and scripting language.
- Understand how Bash interacts with the Linux kernel and command-line tools.
- Identify Bash’s role in WordPress VPS management, automation, and system control.
- Verify whether Bash is installed and identify its version on any Linux system.
1. 5W + 1H Framework
| Question | Explanation |
| What | Bash (Bourne Again Shell) is both a command processor and a programming language for automating Linux tasks. |
| Why | It was created to combine the reliability of the Bourne Shell (sh) with interactive and scripting features from C Shell (csh) and Korn Shell (ksh) — solving incompatibility, usability, and automation limitations. |
| When | Released in 1989, authored by Brian Fox for the GNU Project under the Free Software Foundation. |
| Where | Pre-installed by default on almost every GNU/Linux distribution (Ubuntu, Debian, CentOS, Fedora, Arch). |
| Who | Designed primarily for system administrators, DevOps engineers, and developers automating repetitive CLI tasks. |
| How | Bash reads user input or script files line by line, interprets them, and communicates with the Linux kernel through system calls. |
2. Prerequisites
Before studying this module, ensure you already:
| Requirement | Description |
| Linux Environment | Access to a Linux VPS or local Linux/WSL installation. |
| Basic Navigation Skills | Familiarity with simple commands such as ls, cd, pwd. |
| Terminal Access | Ability to open and run commands in a shell terminal. |
| Sudo Privileges | Needed for installation or configuration if Bash is missing. |
| Curiosity for Automation | Willingness to explore how command sequences become scripts. |
3. Core Concept
Bash is both an interactive shell and a scripting language.
| Mode | Description | Example |
| Interactive Mode | Executes single commands typed directly into the terminal. | ls -al /var/www/ |
| Non-interactive Mode | Executes an entire .sh file line by line. | bash myscript.sh |
Bash provides:
- Consistency → same syntax across distributions.
- Automation → turn repetitive tasks into scripts.
- Control → access to the full power of the Linux kernel and file system.
4. Relevance to WordPress Server Management
| Function Area | Example Use in Bash |
| Automation | Write scripts to restart OpenLiteSpeed, clean cache folders, or schedule backups. |
| Diagnostics | Gather CPU, disk, and memory reports using top, df, or free. |
| Deployment | Copy and configure site files via cp, rsync, and permission commands. |
| Security | Run integrity checks or automate patch-deployment scripts. |
| Logging | Combine echo + redirection to record every maintenance step. |
5. Core Syntax Formula
#!/bin/bash
# Description: Demonstration of a basic Bash script
echo "Hello from Bash!"
echo "Current user: $USER"
echo "Bash version: $BASH_VERSION"
| Line | Explanation |
#!/bin/bash | Shebang — tells the system to interpret this file using the Bash shell. |
# Description: | Comment line ignored by Bash, useful for documentation. |
echo | Built-in command that prints messages to the terminal. |
$USER | Environment variable containing the current username. |
$BASH_VERSION | Built-in variable showing the installed Bash version. |
6. Expected Output
Hello from Bash!
Current user: root
Bash version: 5.1.16(1)-release
(Output varies slightly by system and Bash version.)
7. Implementation Steps
- Open your terminal.
- Create a new file:
nano hello_bash.sh
- Paste the script shown above.
- Save and make executable:
chmod +x hello_bash.sh
- Execute:
./hello_bash.sh
8. Best Practices
| Practice | Reason |
Always include #!/bin/bash | Guarantees execution under Bash regardless of default shell. |
| Begin scripts with comments | Clarifies purpose and authorship. |
| Use lowercase variable names | Avoids conflicts with environment variables. |
| Keep scripts under version control | Enables rollback and collaboration. |
| Check Bash version regularly | Maintain consistency across different VPS environments. |
9. Static vs Dynamic Execution
| Type | Example | Description |
| Static | echo "Welcome Administrator" | Executes constant text or one-time commands. |
| Dynamic | echo "Backup completed on $(date)" | Evaluates real-time commands or variables. |
10. Quick Lab
| Task | Command | Expected Output |
| Check Bash version | bash --version | Displays GNU Bash version information. |
| Identify current shell | echo $0 | Outputs /bin/bash or current shell name. |
| Locate Bash binary | which bash | Returns /usr/bin/bash or installation path. |
| Show current user | echo $USER | Prints logged-in username. |
| List shells available | cat /etc/shells | Lists all installed shells. |
11. Troubleshooting Matrix
| Problem | Likely Cause | Solution |
Permission denied when running script | Script lacks execute permission | Run chmod +x script.sh. |
bash: command not found | Bash package not installed | sudo apt install bash. |
| Script runs in wrong shell | Missing shebang line | Add #!/bin/bash at top. |
| Output shows garbled characters | Locale not UTF-8 | export LANG=en_US.UTF-8. |
12. Cheat Sheet
| Command | Description |
bash --version | Check current Bash version. |
which bash | Display full path to Bash executable. |
echo $0 | Show the shell currently in use. |
echo $BASH_VERSION | Print Bash version variable. |
man bash | View the Bash manual. |
13. Mini-Quiz
- What does “Bash” stand for?
- Who developed Bash and in which year?
- Why is the shebang (
#!/bin/bash) line required in scripts? - Which command displays the Bash version?
- Name one key difference between interactive and non-interactive Bash modes.