`read -p "Enter first string: " VAR1`
`read -p "Enter second string: " VAR2`
`echo "You entered $VAR1"`
`echo "You entered $VAR2"`
`function display()`
`{`
`a=$1`
`b=$2`
if [ '$a' == '$b' ]; then
echo "Strings are equal"
else
echo "Strings are not equal"
fi
`}`
`display VAR1 VAR2`
函数没有给出所需的输出,它总是返回"0";字符串不相等";
- 比较运算符是[取=号,而不是==。请使用=
- 引用"不允许shell解析$,请使用""取而代之的是引号