2 SC2201
koalaman edited this page 2016-12-31 14:00:14 -08:00

Brace expansion doesn't happen in [[ ]]. Use a loop.

Problematic code:

[[ "$file" = index.{htm,html,php} ]] && echo "This is the main file"

Correct code:

for main in index.{htm,html,php}
do
  [[ "$file" = "$main" ]] && echo "This is the main file"
done

Rationale:

Brace expansions doesn't happen in [[ ]]. They will just be interpreted literally.

Instead, use a for loop to iterate over values, and apply your condition to each.

Exceptions:

None.