linux 系统中如何判断字符串是否相同

 

001、

[b20223040323@admin1 test2]$ ls
test.sh
[b20223040323@admin1 test2]$ cat test.sh       ## 测试脚本
#!/bin/bash
a="abc"
b="abc"
if [ $a == $b ]
then
echo "identical"
else
echo "different"
fi
[b20223040323@admin1 test2]$ bash test.sh       ## 执行程序
identical

 

 

002、

[b20223040323@admin1 test2]$ ls
test.sh
[b20223040323@admin1 test2]$ cat test.sh
#!/bin/bash
a="abc"
b="xbc"
if [ $a == $b ]
then
echo "identical"
else
echo "different"
fi
[b20223040323@admin1 test2]$ bash test.sh
different

 

 

003、

[b20223040323@admin1 test2]$ ls
test.sh
[b20223040323@admin1 test2]$ cat test.sh   ## 测试脚本呢
#!/bin/bash
a=$(seq 10 | md5sum)
b=$(seq 10 | md5sum)
if [[ $a == $b ]]         ## 这里加双重中括号的原因是变量a和b中有空格
then
echo "identical"
else
echo "different"
fi
[b20223040323@admin1 test2]$ bash test.sh       ## 执行程序
identical

 

posted @ 2022-10-27 18:51  小鲨鱼2018  阅读(262)  评论(0编辑  收藏  举报