Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

9
  • 1
    I prefer to use T and F to make clear that those aren't real boolean values.
    – phk
    Commented Feb 16, 2018 at 12:57
  • 2
    I can't agree with "always use double brackets in bash". In fact in almost all the scripts I've written I am using single brackets, except when I need to do pattern matching. I think one should understand the difference between [(i.e. test) and [[ and use the one that is suitable for his need. Commented May 12, 2020 at 12:43
  • @WeijunZhou mind elaborating in which cases single brackets are better?
    – Hugo G
    Commented May 12, 2020 at 23:07
  • 2
    @WeijunZhou Your example is a strong argument against single square brackets. It makes the code much harder to understand and opens the window wide open to errors. Double brackets are more strict and encourage cleaner code.
    – Hugo G
    Commented May 13, 2020 at 4:47
  • 2
    This answer above all the others helped me understand some core concepts. The idea that [ is a built-in that returns an exit code based on evaluating its expression is important; and the "aha" moment for me is the builtins true, and false, are the same. Thus, you can do simple boolean checks if you assign true or false directly to variables and use them without brackets: if $my_bool ; then or $my_bool && echo "Print this". Exit code 0 and exit code 1, that's all you get from your true/false here. Clicked for me. Thanks!
    – xxx
    Commented Jul 7, 2023 at 1:17