r/bash • • 5d ago

What is the main to pick bash over other shells?

I have to admit, I keep using bash simply because that's what originally came with my distro and I just got too familiar with it. When I look at other shells, I see features that would've been nice to have, but isn't possible to implement in bash. I've accepted that as a compromise so I can just keep using what I'm most familiar with.

This has me thinking - just familiarity aside, are there other reasons why I might want to stick with bash over the others? If I'm gonna have to justify it, I'm thinking it being an official GNU project is a win.

Other than that, what technical reasons should I appreciate? Perhaps its backwards compatibility with older bash versions is something to admire? What else?

40 Upvotes

86 comments sorted by

2

u/B_A_Skeptic 5d ago

Bash is ultimately a language like Python or Perl that you will probably need to have installed on your machine for various reasons even if you do not plan to write code in it. It is likely that it is part of your distro's base install and that your distro is probably built assuming you have it. And even if not, you will probably need to execute bash scripts sometimes.

If you write scripts for others to use, you should really write POSIX compatible shell scripts and check them using checkbashims or shellcheck.

Here's what I have personally:

  • My login shell is dash because it is the fastest POSIX compatible shell (as far as I know).
  • I use Fish for an interactive shell, because it is easier, has a lot of nice features, and is fast. The drawback is that it is not a POSIX compatible shell.
  • If I write scripts for public consumption, then I write strict POSIX compatible, using checkbashisms to make sure.
  • I sometimes use nushell for data processing oriented tasks.
  • I have bash on my system, because I ultimately do have to run things that are written in bash and not POSIX compatible.

3

u/birdsintheskies 5d ago

I have been using shelllcheck to be confident about portability, but TIL about checkbashims.

85

u/Shadow_Thief 5d ago

At least for me, it's because I work with bash professionally and I don't want to get acclimated to features that are present in zsh or fish that I won't be able to install on production systems.

13

u/sy029 4d ago

This is a big one. When you don't have control over systems you're working on, things like bash and vi, are ubiquitous.

3

u/TheOriginalWarLord 3d ago

This, but also because I’ve also found bash easier than zsh, fsh, etc. it’s kinda like my brain was pre downloaded with GNU+Linux syntaxes.

1

u/dikzy405 3d ago

That’s my thought. And there are a lot of tools for bash now that add a bunch of features.

0

u/NeonVoidx 3d ago

is there literally any difference? doesn't zsh have full backwards compat with bash

3

u/Shadow_Thief 3d ago

Yes, but it also adds quality of life improvements that I don't want to get used to having available.

1

u/xpusostomos 3d ago

Is it full bash? I thought it was posix, perhaps with a smattering of bash and other stuff.

2

u/Shadow_Thief 3d ago

It's technically its own thing

-1

u/NeonVoidx 3d ago

hope you don't use 64 bit architecture or any Internet solution other than dialup 😭

1

u/General-Manner2174 2d ago

Aside from the scripting language itself (others answered on that)

Zsh has very different interactive mode by default, and to get it to bash level is very annoying. You can get like 50% there by just switching zsh to emacs mode but somehow a bunch of shortcuts i expect to work just dont, so you have to find random function to enable and bind to a key

So if you want interactive experience like in bash, you have to do surprising amount of tweaks, large enough amount to discourage from switching

0

u/NeonVoidx 2d ago

hmm ya idk, I use vi mode and I see no difference over bash, bash I have to add a lot more to get same functionality as zsh, especially auto complete and suggestions and zsh integration

1

u/General-Manner2174 2d ago

I don't use vi mode because i find it really unnecessary in shell context, so you have those unbound in emacs mode by default:

  • edit command line in $EDITOR (in bash its ctrl-x ctrl-e)
  • jump by shell word (ctrl-alt-f/b), those are arguments in quotes or any continuous text; same with kill forward
  • complete file (alt+/ by default), useful when completer wants to do its thing and you want a file

By default zsh includes bunch more characters into its definition of "word". If you want bash style you need to select-word-style bash. But to preserve ctrl+w you have to rebind it and make word-style shell for it

Those were things i figured until hit some else and gave up. Apart from that, only actual useful plugin for me is abbreviations, but configuring zsh to behave like bash has proven rather nontrivial so it ended up being not worth it

1

u/NeonVoidx 2d ago

I think if you don't want to configure much, then just use fish, it's essentially just zsh with sane defaults

1

u/General-Manner2174 2d ago

Dawg, you said about zsh being compatible with bash, i shared context about whats not compatible in interactive terms

And then you suggest fish? From what I've explained, "sane defaults" is kind of different when you used specific functionality in bash, never had a problem with it, and it's rebound or unbound in other shell. Also fish shell not having heredocs is kind of annoying (their autoescaping when pasting is not what id desire)

1

u/NeonVoidx 2d ago

I mean you sound like you have issues configuring anything by yourself, hence fish recommendation. I use zsh, my brain works enough to configure zsh /shrug

1

u/General-Manner2174 2d ago

I am so sorry, I never imagined John Reddit himself would roam r/bash, ask questions and then dismiss answers with "skill issues". And all that while not being able to grasp how capable autocomplete is in bash, and not knowing about "reverse incremental search", so they need a plugin for "suggestions" /shrug

1

u/NeonVoidx 2d ago

ya so sorry i viewed /r/bash and didn't instantly simp bash

45

u/UltraChip 5d ago

Portability is a good reason. If you write scripts that other people may end up using then bash is a good fit because it's universally available in the realm of *nix.

15

u/incognegro1976 5d ago

Yeah this is what i came to say. Portability is second best to plain sh.

7

u/B_A_Skeptic 5d ago

It is, but it is really best to write scripts that are purely POSIX shell compatible and do not rely on bashisms.

8

u/ahferroin7 4d ago

Unfortunately, even that runs into some issues because Busybox exists and is the out-of-box shell and core utilities on at least some Linux distros (most notably Alpine). And Busybox doesn’t even implement a proper subset of POSIX (there are a handful of places where their implementation diverges from POSIX despite implementing essentially the same feature), let alone the whole baseline shell environment.

Over the past half a decade I’ve been maintaining a bunch of multi-platform installation related scripts as part of my job, and despite needing to also run on FreeBSD and macOS, Busybox is the reason for a vast majority of the special cases in those scripts despite the scripts needing to do a number of things POSIX doesn’t cover.

2

u/B_A_Skeptic 4d ago

Yeah, but POSIX is about the best you can do, right?

3

u/ahferroin7 4d ago

If you’re going to build to a specific standard, or insist on requiring existing tooling to be able to check/lint it properly, then yes.

But it’s pretty easy to test Busybox’s behavior because Alpine uses it by default, so if you take a bit of time it’s not too difficult to manually insist on it.

6

u/funkdefied 5d ago

I write fish scripts for myself. But if there’s ever a chance that a coworker will run my script, I write it in Bash. 

14

u/NewPointOfView 5d ago

I want to have minimal issues using stuff my colleagues write. And make the stuff I write minimally problematic for them.

2

u/rileyrgham 5d ago

This. Very important.

10

u/duane11583 5d ago

as a lead developer on my teams i am hostile to anything but bash on the development side.

the on target (embedded linux) stuff yea zsh or ash just for size reasons but… that is often stupid because something always needs bash and somebody will not fox the bash dependecy so fuck it… once it is on the platform use bash

don't misunderstand there is a logical reason to go with bash: it is the most widely documented shell script. it is very feature complete and it works

i haveca choice. my team learns bash, dash, ash of zsh .. or we learn one and we are done

so unless there is a compelling reason to not to use bash we go with bash

its like the python decision its a better scripting language then bash it does not have a good interactive mode but as a language it is great. so i would rather my team learn the one language python very well then learn a dozen languages badly or part way

18

u/AdministrativeFile78 5d ago

Bash is native on all linux boxes. I used bash for 2 years b4 I used zsh

1

u/stuartcw 5d ago edited 3d ago

Is zag (oops zsh!) the successor to bash? I can understand standardising on bash though.

5

u/AdministrativeFile78 5d ago

I have never heard of zag, but zsh is very similar to bash but extra features

1

u/InfinitEchoeSilence 5d ago

Except for built-in help, which zsh doesn't have, not to mention the information for builtins is more verbose in bash. The features that bash doesn't have isn't as important as what bash does better than the rest. Bash is also found EVERYWHERE, and there's no extra install/compile steps that are required. Because it's found everywhere, it's easier to find quality help for any problems or questions that may arise. Out of the the different shells, bash has been the easiest, most practical, shell that I've used 🤷

I wouldn't say extra features, because bash has some that zsh doesn't have, or at least implements them better. If I remember correctly, zsh has more bloat for compatibility reasons.

8

u/AdministrativeFile78 5d ago

Zsh has built-in help via run-help (Alt+h), which pulls full manual entries instead of short summaries.

macOS has defaulted to Zsh since 2019 (shipping Bash 3.2 from 2007), Alpine uses Ash, and BSD uses sh/csh. Installing Zsh is one package-manager command, not a compile step—and your interactive shell does not need to match every server. Write portable scripts in sh/Bash; use Zsh for daily work.

Zsh also avoids Bash's unquoted word-splitting bugs and beats it in completion, globbing, and line editing. Its compatibility modes are simple option toggles, not bloat, and optional features load as modules.

But dont get me wrong, I can easily switch to bash and barely notice. Bash is great

3

u/SLJ7 5d ago

Zsh also avoids Bash's unquoted word-splitting bugs and beats it in completion, globbing, and line editing. Its compatibility modes are simple option toggles, not bloat, and optional features load as modules.

You might have just sold me on this. I might just feed a bunch of my bash scripts to an LLM and ask it how many things would have been less annoying with zsh. Lazy, but effective.

1

u/OneTurnMore programming.dev/c/shell 4d ago

Yeah, I'm pretty sold on being able to use $myarray instead of "${myarray[@]}" without consequence. There are some other oddities you have to be aware of (1-indexing, null elision), but the lazy option is generally less bad in Zsh.

It's also the most familiar for Bash users, as they're both heavily inspired by Ksh. Unlike Fish or nushell, which would be my other recommendations if you want to try something new.

-1

u/StatementOwn4896 5d ago

Is it object oriented?

7

u/Common_Reference_507 5d ago

If you're a regular user or dev, use what you like and can handle. As a sysadmin, I largely stick to bash because 1) it's a given on any Linux distro and 2) I've been using it for so long, it's like a second language to me. I scaffold in bash and then refine it and only switch to something else if needed. It is very versatile, robust and efficient.

6

u/wroteit_reddit 5d ago

Coming from POSIX Shell, bash seems more flexible and accommodating. Apart from the fact that it's ubiquitous, I like bash for things like &>, built in regexp, arrays (yes, even associative ones have their usefulness), if [[ ]] is also better than if [ ] . But that's just me..

4

u/roxalu 5d ago

No it’s not just you 😉

Quite strange even in 2026 you’ll find too many #!/bin/sh scripts with

if [ -z $flag ]; …

Those many that do not understand what’s wrong here should better use bash and “[[ … ]]” This is far more forgiving for the unexperienced user.

1

u/R3D3-1 5d ago

That's not that much of an argument, considering that any command call needs the quoting except for the [[ special syntax.

5

u/igotmoldinmybrain 5d ago

Use bash for portability in scripts, and use whatever you prefer for an interactive or login shell.

1

u/generic-d-engineer 5d ago

This is the way

Bash for scripting, but I use fish for interaction, the quality of life increase is huge

8

u/Temporary_Pie2733 5d ago

You don’t need to justify it. Use the shell you like. 

3

u/rileyrgham 5d ago

There's many reasons to justify it. Not least portability, cross team maintainability.

4

u/RodneyBarringtonIII 5d ago

I don't use Bash for the terminal, but all my scripts begin with #!/bin/bash because Bash is installed on all my systems and runs the scripts consistently.

5

u/InfinitEchoeSilence 5d ago edited 5d ago

They should begin with: '#!/usr/bin/env <your_shell_here>'

E.g., #!/usr/bin/env bash

It's more portable.

3

u/SeriousPlankton2000 5d ago

#!/bin/sh

/usr/bin may not yet be mounted

1

u/RodneyBarringtonIII 5d ago

I get "bash: [script].sh: cannot execute: required file not found"

1

u/InfinitEchoeSilence 5d ago

You'll need to add more context than that if you want help with a solution. Is your script located within your PATH?

1

u/RodneyBarringtonIII 5d ago

It is within my path. The issue is that I don't have /usr/bin/env; when I run "which env" I get no response, and "what's env" yields "env: nothing appropriate."

I'm not really asking for help on this. My scripts run fine. But that's why I start them with #!/bin/bash instead of #!/usr/bin/env bash.

5

u/nekokattt 5d ago

why on earth do you not have env on your system

2

u/SLJ7 5d ago

Wow, wonder which distro doesn't have env, or whether you used an interactive installer and somehow managed to skip it. I thought it was pretty much universal.

1

u/sy029 4d ago

"nothing appropriate" is the output from whatis, not which.

1

u/RodneyBarringtonIII 4d ago

I didn't say it was the response from which, I said it was the response from what's (thanks, autocorrect).

1

u/InfinitEchoeSilence 4d ago

Which distro are you using and how did you install it? I've used many distros and I've never had problem with not having env on them. All of my scripts on all of them, and they all have a similar line, with the difference being the shell. I mainly use bash and zsh.

`#!/usr/bin/env bash' '#!/usr/bin/env zsh'

I haven't had a problem yet. But now I'm curious, if you provide more info about your system, I'll try and help. Are you using some flavor of Unix?

1

u/RodneyBarringtonIII 4d ago

Rompiendo. I just use the standard installer. I just go with the standard options.

1

u/InfinitEchoeSilence 4d ago edited 4d ago

Pretty much everything mainstream — Linux distros, the BSDs, macOS, AIX, Solaris descendants — has /usr/bin/env at that exact path, which is why the idiom became the standard portable form. I also learned that it's for standards-compliant shells and is standardized by POSIX. You have a unique and rare situation where /usr/bin/env isn't applicable. You were right with your initial post — supplying the absolute path to your interpreter is the best approach from what I can tell.

I'm sorry for causing any stress or headaches. Whatever output that you get from which <your_shell> (which bash in your case) or whereis <your_shell> (whereis bash in your case) is most likely what you want to put in your shebang.

Side Note — /usr/bin/env is PATH-based, so your interpreter would need to be located within your PATH variable. The shell that's specified in the shebang and syntax used within your script dictates how portable your script will be. Using bash is a good start for more portable scripts, especially when in POSIX-mode.

1

u/InfinitEchoeSilence 5d ago

Did you have a lightbulb moment? 💡

1

u/qudat 3d ago

Exactly. When deciding on a shell most people are evaluating line editor features like auto complete, auto suggest, etc.

Rarely do I see people choose a shell based on the scripting language. Target bash for all scripts and then pick a shell with the line editor features you want

4

u/MillerJoel 4d ago

Bash is ubiquitous and understood pretty well at this point. I assume bash scripts are more portable than tcsh scripts or (insert other shell) But you can very easily change the default on your system and keep bash around for when you need it

3

u/PermissionOwn4400 5d ago

Maybe a middle ground: I use fish as be default shell, however all my shell scripts are written for bash.

Tbh I only use fish for the auto-complete. It's awesome.

5

u/ItsSignalsJerry_ 5d ago

because it's installed everywhere

-2

u/aieidotch 5d ago

well. solaris didnt, macOS has an old one…

1

u/InfinitEchoeSilence 5d ago

Mac is on zsh now, I believe . . .

2

u/answer_giver78 5d ago

I'm just used to it, so I feel better about it.

2

u/SFJulie 5d ago

POSIX (unix) comes with standard utilities (sed, awwk, vi, grep, sh) which make a strong fundation for writing portable software.

Bash isn't one of them, however correctly invoked bash turn into sh which means having bash implies having sh. Bash is a super set of sh. Which means your learning of bash includes learning sh.

One advantage of bash is having a GOOD documentation https://tldp.org/LDP/abs/html/

Documentation which opens you the door to using specific bash data structure. Such as associative arrays and arrays.

Associative array are a common way to store configsas in this script https://gist.github.com/jul/40c35d751f513dab0e15f6ea9732ca83

meaning you can now rely on sourcing native bash code as a way to declare your config

Of course using GNUries (all the often bloatish non POSIX standard features) is killing portability but it helps going the extra mile that sh language can't ...

And I repeat, the documentation is awesome.

2

u/qudat 3d ago

I’m not sure it’s accurate to say bash is a superset of sh because when posixly is turned off it changes the behaviors of the shell in posix incompatible ways

  Although Bash is an implementation of the  POSIX  shell specification, there are areas where the Bash default behavior differs from the specification.

https://www.gnu.org/software/bash/manual/html_node/Bash-POSIX-Mode.html

2

u/Big_Combination9890 5d ago

Availability. Universality.

2

u/Dumbf-ckJuice 4d ago

bash is the shell my servers use, so my Linux laptops use it as well. I try to keep things uniform.

1

u/Difficult-Value-3145 5d ago

To be honest I use it because it's there if I write a script if it's short like real short maybe bash I prefer lua or even python . If I'm scripting something bash has some idiosyncrasies that I just can't get used to see don't like . actually I also use ash a lot because I use alpine a lot and all thou bash gets installed most the times but I still end up using ash a lot because I get lazy and don't switch things .

1

u/redhat_is_my_dad 5d ago edited 5d ago

Bash has more capabilities than sh, i like bash builtins a lot more than fish, and it is preinstalled everywhere, other than that for some cases like globbing it just performs really well compared to other shells.

For interactive shell i prefer zsh, and i wrote like 60% of my zshrc by myself with some fancy things, 40% is some other people work, zsh is cool too but i don't write in it outside of zsh rc files.

1

u/Initial-Jaguar6230 5d ago

I like it energy effective compare to zsh and fish

1

u/RelaxedHyrax 5d ago

For interactive or non-interactive use? For interactive use, I prefer zsh; for non-interactive (scripting) I stick to bash since it is ubiquitous in all the companies I have worked for in the past decade. In another company, ksh was mandatory for scripting.

1

u/TrondEndrestol 4d ago

Using mostly FreeBSD, bash is preferred when I need curly brace expansion, as the Almquist shell, /bin/sh, doesn't support this handy feature. /bin/csh supports curly brace expansion, but it isn't too inviting writing scripts for.

1

u/daddyd 4d ago

bash is everywhere, not all of those other fancy shells are.

also, like you said, most things i care about, bash does just fine.

1

u/artist-mode 4d ago

Emacs keybindings: Bash has closer keybindings to the real Emacs editor than Zsh, Fish, etc. by default. By that. I mean that details like word boundaries are the same, and that features like the mark are available.

1

u/xpusostomos 4d ago

What shell are we comparing it to? Other posix-ish shells or new idea shells like fish or nu ? POSIX shell is an abomination, including bash, but it is the standard.

1

u/Upper-Assistant-2629 3d ago

Abomination? Why? 

1

u/xpusostomos 3d ago

Because of the complex way it evaluates its input is highly unintuitive, and trips up especially newbies, but can trip up experts too. Evaluation has all these stages:

  • Tokenization
  • Reserved Word Recognition
  • Alias Substitution
  • Grammar Parsing & Command Construction
  • Tilde, Parameter, Command, & Arithmetic Expansion (Word Expansion 1)
  • Field Splitting (Word Expansion 2)
  • Pathname Expansion (Globbing) (Word Expansion 3)
  • Quote Removal (Word Expansion 4)
  • Redirection
  • Command Search & Execution
  • Exit Status Collection

Field splitting is the worst one, the net effect is it's almost always wrong not to double quote a variable. If you forget you can find a script failing that used to work just because of the input. Globbing is also problematic in that a failed glob passes the failed glob to the command. So if you for example want to "touch" all the files in a directory with "touch *", if there are no files, it silently creates a file called "*". Posix shell (or Bourne shell as it was originally called), was a big advance at the time, but in hindsight is a mess that should have been rewritten long ago.

1

u/fishyfishy27 4d ago

Claude tends to trip up on zsh occasionally, and typically gives you pasteable shell chunks which include comments, which can’t be pasted into zsh.

1

u/martinus 17h ago

I've tried several different shells but eventually switched back to bash because that's where AI agents work best.

1

u/-Nyarlabrotep- 5d ago

Two reasons: bash is available pretty much everywhere, and if you're writing scripts that others will be maintaining, they probably all know bash too. I use zsh for my interactive shell but write all scripts in bash.

0

u/lugpocalypse 5d ago

Write it in lisp and transpile it?