news.volyx.in

test, [, and [[ (2020) (jmmv.dev)

548 points by mattrighetti · 1003 days ago · 225 comments on HN

Article summary

The article discusses the Unix binaries 'test' and '[', which are used to evaluate expressions in shell scripts. These binaries are often implemented as built-ins in shells, but can also be external commands. The article also mentions '[[' as a Bash extension that replaces '[', with some differences in behavior. The choice of which to use depends on the specific use case and the need for portability or Bash-specific features.

Main themes

  • Unix shell scripting
  • Portability and compatibility
  • Bash vs POSIX shell
  • Scripting language choice
  • Security and minimal environments
  • Shell script best practices

What commenters say

  • Using Bash is not always an option, especially when writing scripts that need to run on a variety of Unix platforms.
  • Some argue that avoiding Bash and using POSIX shell is a good practice for portability and simplicity.
  • Others believe that using Bash is acceptable and even preferable when writing scripts that will only run on Bash-specific environments.
  • There are valid reasons to avoid installing Bash, such as security concerns and the need to keep image sizes small in minimal environments.
  • The use of '[[' is generally recommended when writing Bash-specific scripts, due to its additional features and consistent behavior.
  • Some developers prefer to use a 'real' programming language instead of shell scripts for more complex tasks.
  • The choice of shell and scripting language ultimately depends on the context and requirements of the project.