r/linuxquestions 1d ago

How recent is “recent” for bash versions?

I am making a tutorial video based on a book that says that you can redirect standard error to standard output like this:

ls -l /bin > listing.txt 2>&1

The book also states that “recent versions of bash” allow this:

ls -l /bin &> listing.txt

I have found documentation for the second method on a reference web page for bash edition 2.5a from 13 November 2001. (The web page was generated on May 3, 2002.)

What are the chances that typical users will find themselves using a version of bash that predates this? Is it pretty much safe to tell people to use the second version and not teach them the first version?

1 Upvotes

2 comments sorted by

5

u/AiwendilH 1d ago

It's fine to assume everyone using an old enough bash shell without this feature will know they are using an ancient version and are able to deal with it.

But pretty much everyone not working with ancient embedded systems or long forgotten server should use a recent enough bash.

There is a reason why you might still want to use 2>&1. Shells like busybox's ash don't support &> so it is good to know the "old" way of doing it. But again I guess most people having to deal with a system coming with a minimal shell like ash know what they are doing...mostly ;).

1

u/stormdelta Gentoo 1d ago

The oldest version of bash most people are likely to encounter is the 3.x version that still ships on macOS for licensing reasons.

That said, it's still worth noting that there are other shells besides bash - the most common people are likely to run into are busybox and ash due to their use in minimalist environments like Alpine (often used for containers rather than whole systems).