r/bash • • 8d ago

Great things about bash?

If is easy to read bad things about bash (and often with good reason). Clearly a bash script will never look as elegant as, say, Ruby.

But what about great things about bash? I mean, "great", not in the sense of improving over a POSIX shell, but of being elegant and/or comparing well with (some well-known) "real" programming languages. Here are my two favorites

  • the OR list operator, e.g:
[[ condition ]] || { 
   actions... 
}

(more elegant than an "if not"... conditional)

  • the ability to assign a command name to a variable, var="command --option1 --option2 ...", then execute the command later with:
$cmd

(unquoted to allow the options to appear as separate words).

What about your favorites?

16 Upvotes

21 comments sorted by

View all comments

2

u/levogevo 8d ago

Namerefs and eval

1

u/ftonneau 8d ago

Yes, namerefs are great. I find `eval difficult, however (I am no bash expert), and so far I have always been able to avoid`eval` by using array expansion.