如何读取字符串变量并将其与 bash 中的字符串常量进行比较

How to read a string variable and compare it with string constant in bash

我需要读取一个字符串变量并检查它是否等于字符串 'qwe'。 我试试这个代码:

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

但终端显示

[rwx : command not found

[ 是一个 命令 ,而不仅仅是语法。命令需要用空格与其参数分开:

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

在交互式提示中查看 help if

$ 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...

里面没有关于 [...] 的内容,if 之后是 命令列表 退出状态 决定条件的“成功”。