首页 > 系统相关 >linux 系统中如何判断字符串是否相同

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

时间:2022-10-27 19:01:47浏览次数:41  
标签:test2 相同 echo admin1 test sh b20223040323 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

 

标签:test2,相同,echo,admin1,test,sh,b20223040323,linux,字符串
From: https://www.cnblogs.com/liujiaxin2018/p/16833339.html

相关文章