Skip to main content
added 50 characters in body
Source Link
nxnev
  • 3.8k
  • 2
  • 15
  • 29
  • [ is a command (basically a variant of the test command). [[ is a builtin in many shells.
  • When you write foo* inside [...], filename expansion (aka globbing) occurs; while inside [[...]] pattern matching occurs.
  • [[ is more powerful and capable than [ but should not be used if portability is a concern.
  • [ and [[ are not part of the if syntax, you can use them as in [ "$exit" = 'yes' ] && exit.
  • Inside [...] you should prefer = instead of ==. As far as I know, the second one is accepted in many shells but is not POSIX-compliant.

By the way, I recommend you to double-quote your variables even if you really know how word splitting will behave.

  • [ is a command (basically a variant of the test command). [[ is a builtin in many shells.
  • When you write foo* inside [...], filename expansion (aka globbing) occurs; while inside [[...]] pattern matching occurs.
  • [[ is more powerful and capable than [.
  • [ and [[ are not part of the if syntax, you can use them as in [ "$exit" = 'yes' ] && exit.
  • Inside [...] you should prefer = instead of ==. As far as I know, the second one is accepted in many shells but is not POSIX-compliant.

By the way, I recommend you to double-quote your variables even if you really know how word splitting will behave.

  • [ is a command (basically a variant of the test command). [[ is a builtin in many shells.
  • When you write foo* inside [...] filename expansion (aka globbing) occurs; while inside [[...]] pattern matching occurs.
  • [[ is more powerful and capable than [ but should not be used if portability is a concern.
  • [ and [[ are not part of the if syntax, you can use them as in [ "$exit" = 'yes' ] && exit.
  • Inside [...] you should prefer = instead of ==. As far as I know, the second one is accepted in many shells but is not POSIX-compliant.

By the way, I recommend you to double-quote your variables even if you really know how word splitting will behave.

Source Link
nxnev
  • 3.8k
  • 2
  • 15
  • 29

  • [ is a command (basically a variant of the test command). [[ is a builtin in many shells.
  • When you write foo* inside [...], filename expansion (aka globbing) occurs; while inside [[...]] pattern matching occurs.
  • [[ is more powerful and capable than [.
  • [ and [[ are not part of the if syntax, you can use them as in [ "$exit" = 'yes' ] && exit.
  • Inside [...] you should prefer = instead of ==. As far as I know, the second one is accepted in many shells but is not POSIX-compliant.

By the way, I recommend you to double-quote your variables even if you really know how word splitting will behave.