busybox shell error: line 9 (left square bracket): not found

busybox shell error: line 9 (left square bracket): not found

我有以下代码,但出现错误“第 9 行:[:未找到”:

#!/bin/sh
msg=$(dmesg | tail -n1)
echo "$msg"
if [ "$msg" = "Tasklet grp12" ]
then
    echo "Test was successful, Strings are equal."
else
    echo "Test failed, Strings are not equal."
fi

感谢查尔斯·达菲!我必须在 busybox 的 make menuconfig 菜单的 shell 部分选中“'test' 的内置版本”框,以启用字符串比较。现在代码可以工作了。 因为我激活了 grep,所以我首先尝试了另一种解决方案,它也有效但性能肯定很差:

#!/bin/sh
msg=$(dmesg | tail -n1)
echo "$msg"
tasklet="Tasklet grp12"
if ( echo "$msg" | grep "^$tasklet$" )
then
    echo "Test was successful, Strings are equal."
else
    echo "Test failed, Strings are not equal."
fi