Still the [ ] (test command) is a challenge in case the tested variable contains a test operator, for exanple
or
and
Code:
if [ "$file1" = "foo" ]
Workarounds
1. Prepend an extra string, I use it outside the quotes to emphasize it's extra
Code:
if [ x"$file1" = x"foo" ]
2. Or switch the order, put the constant first
Code:
if [ "foo" = "$file1" ]
3. Or use the [[ ]] compound that is not a command and is easier to parse, and has less pitfalls for beginners
Code:
if [[ "$file1" = "foo" ]]