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.

Required fields*

5
  • 1
    Note that single bracket supports the -a instead of &&, so one can write: [ -L $file -a -f $file ], which is the same number of characters within the brackets without the extra [ and ]... Commented Aug 27, 2016 at 23:34
  • 9
    @AlexisWilke The operators -a and -o are problematic because they can lead to incorrect parses if some of the operands involved look like operators. That's why I don't mention them: they have zero advantage and don't always work. And never write unquoted variable expansions without a good reason: [[ -L $file -a -f $file ]] is fine but with single brackets you need [ -L "$file" -a -f "$file" ] (which is ok e.g. if $file always starts with / or ./). Commented Aug 27, 2016 at 23:38
  • Note that it's [[ -L $file && -f $file ]] (no -a with the [[...]] variant). Commented Nov 30, 2017 at 15:25
  • The part about braces being keywords is important. It's what allows you to do things like: { task1 && task2 && task3 && echo "Success!"; } || { echo "One of the tasks failed!"; exit 1; } in a larger script. If you use parentheses, exit 1 will just exit out of a subshell and any surrounding script will keep running. Without the ending semicolon in each set of braces, you'll get "Unexpected end of file". Commented May 18, 2023 at 22:54
  • The examples make the better answer. Commented Sep 12, 2023 at 10:48