我正在尝试接受两个字符串输入并检查它们是否相等,如果不相等则告诉字符长度。我键入两个字符串后,我找不到错误,有人能说出我做错了什么吗?我尝试使用:
WHERE b.machine_id = 1
答案 0 :(得分:1)
这个将完全按预期工作:
#!/bin/bash
while true; do
echo "Please Enter two name to compare"
read name_1 name_2
one=${#name_1}
two=${#name_2}
if [ "$name_1" = "$name_2" ]
then
echo "$name_1 and $name_2 are equal"
else
echo "$name_1 and $name_2 are not equal"
fi
echo "String 1 length is $one"
echo "String 2 length is $two"
done
答案 1 :(得分:1)
点数:
bash
中的用户定义变量不能以数字开头,因此显然不能只是数字
-eq
进行算术比较;当您使用=
(POSIX)或==
答案 2 :(得分:0)
尝试以下方法。我在[[ ]]
周围使用了if
,并将变量从1
和2
更改为x
和y
:
#!/bin/bash
while true; do
echo "Please Enter two name to compare"
read name_1 name_2
x=${#name_1}
y=${#name_2}
if [[ "$name_1" == "$name_2" ]]
then
echo "$name_1 and $name_2 are equal"
else
echo "$name_1 and $name_2 are not equal"
fi
echo "String 1 length is $x"
echo "String 2 length is $y"
done
exit