0

Inside [[ ]] I do not need to quote variables right?

Rather than

if [[ "$flrm" == *"org"* || "$flrm" == "all" ]]; then
  printf '%s\n' "Delete: $fl"
fi

I can do

if [[ $flrm == *"org"* || $flrm == "all" ]]; then
  printf '%s\n' "Delete: $fl"
fi
Vera
  • 1,223
  • 3
    Does this answer your question? When is double-quoting necessary?. See in particular the section "Where you can omit the double quotes" of @Gilles' answer. – AdminBee Oct 21 '21 at 07:48
  • It says that within double brackets (which are shell special syntax) quoting is not required, except where a pattern or regular expression is expected on the right-hand side of =, ==, !=, or =~. – Vera Oct 21 '21 at 07:54
  • This would mean that [[ prevents word splitting of variable values, contrary to ['. – Vera Oct 21 '21 at 08:02
  • With single brackets [ ], I have seen people using if [ $var = "test" ] and if [ $var == "test" ]. I do not think there is a difference, or am I wrong? – Vera Oct 21 '21 at 08:08
  • @AdminBee All shells that support [[ … ]] support both = and ==, so neither it more correct than the other. Ksh documents = as deprecated. Mksh documents == as deprecated. Bash and zsh recommend them equally (when inside double brackets). However, inside single brackets or after test, = is preferable because most shells that don't support double brackets, and standalone test implementations, only recognize =. – Gilles 'SO- stop being evil' Oct 21 '21 at 09:09

0 Answers0