'How to read a string variable and compare it with string constant in bash [duplicate]

I need to read a string variable and to check if it's equal to string 'qwe'. I try this code:

read VAR1
if ["$VAR1" == "rwx"]; then
    current=$current+1
fi

but terminal says

[rwx : command not found



Solution 1:[1]

[ is a command, not just syntax. Commands need to be separated from their arguments with whitespace:

if [ "$VAR1" = "rwx" ]; then ...
#   ^               ^

See help if at an interactive prompt:

$ help if
if: if COMMANDS; then COMMANDS; [ elif COMMANDS; then COMMANDS; ]... [ else COMMANDS; ] fi
    Execute commands based on conditional.

    The `if COMMANDS' list is executed.  If its exit status is zero, then the
    `then COMMANDS' list is executed...

There's nothing in there about [...], what comes after if is a command list, and the exit status determines the "success" of the conditional.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1