Advanced Bash Scripting

Introduction

Shell scripting vs Bash scripting

Shell scripting is the practice of writing executable text files that interpret and execute commands in a Unix-like shell. While Bash (Bourne Again SHell) is the most common shell today, there are many others:

ShellYear IntroducedKey Feature
Bourne sh1979Original shell scripting standard
Bash1989Rich scripting constructs
Z shell zsh1990Typo correction & plugin system
Korn ksh1983Advanced variables & functions
Dash1997Focus on speed & minimalism

Use shell scripting when referring to any shell. If you depend on Bash-specific features (arrays, [[ … ]], process substitution), say shell scripting with Bash.

Note

Always include a shebang (#!) at the top of your scripts to declare which shell to use:

#!/usr/bin/env bash

When to Use “Shell” vs. “Bash” Scripting

  • Shell scripting – generic term for writing scripts in any shell
  • Shell scripting with Bash – when your code relies on Bash-only features
  • Shell scripting with zsh, ksh, etc. – when targeting those environments

Illustrative Differences Between Bash and Other Shells

Below are two examples that show how Bash and other shells (like sh and zsh) can behave differently.

1. zsh Autocorrects Typos

Zsh offers a user‐friendly autocorrect feature:

$ LS -l FILE.TXT
file.txt

Here, zsh automatically corrects LSls and FILE.TXTfile.txt. Bash does not do this by default.

2. echo -n Behavior

The -n flag suppresses the trailing newline in Bash, but not in all sh implementations:

# In Bash
$ echo -n "Hello"; echo "END"
HelloEND

# In sh
$ sh -c 'echo -n "Hello"; echo "END"'
-n Hello
END
  • Under sh, -n is treated as text and printed.
  • Under bash, -n removes the newline as expected.

Warning

For portable scripts, avoid relying on echo -n. Use printf instead:

printf "Hello"; echo "END"

Conclusion

  • Refer to any interpreter as shell scripting when you don’t need to specify.
  • Use shell scripting with Bash (or another shell) if you rely on that shell’s extensions.
  • For maximum portability and advanced features, Bash is the de facto standard.

Watch Video

Watch video content

Previous
Interactive vs non interactive shell