I have written below script:
#!/usr/bin/bash
STR_1="nfosys"
STR_2="Infosys"
if (( $STR_1 == $STR_2 ))
then
echo "Strings are equal"
else
echo "Strings are not equal"
fi
Getting Output:
root:~/Desktop/user_repo/Demo# bash -x test.sh
+ STR_1=nfosys
+ STR_2=Infosys
+ (( nfosys == Infosys ))
+ echo 'Strings are equal'
Strings are equal
root:~/Desktop/user_repo/Demo#
Ideally it should print "Strings are not equal" statment but i am unable to understand why it is printing "Strings are equal"
nfosys
andInfosys
are being obtained and what they actually are while the script is being run. – Nasir Riley Mar 27 '22 at 15:32==
inside of(())
is used for comparing numbers, use[[
instead for strings. – jordanm Mar 27 '22 at 15:41test.sh: 6: [[: not found
Strings are not equal root@ip-10-0-45-44:~#
– Poonam Mar 27 '22 at 15:49bash
, notsh
. Or rather,chmod +x test.sh
and./test.sh
so that the hashbang line applies. See: Does the shebang determine the shell which runs the script? – ilkkachu Mar 27 '22 at 15:53