- =
- ==
- equals
1 Bash[ | ]
Bash
Copy
i=1
j=2
if [ "$i" = "$j" ]
then
echo "i == j"
else
echo "i != j"
fi
# i != j
Bash
Copy
i=1
j=2
if [ "$i" = "$j" ]; then echo YES; else echo NO; fi
if [ $i = $j ]; then echo YES; else echo NO; fi
if [ $i -eq $j ]; then echo YES; else echo NO; fi
# NO
# NO
# NO
Bash
Copy
i=2
j=2
if [ "$i" = "$j" ]; then echo YES; else echo NO; fi
if [ $i = $j ]; then echo YES; else echo NO; fi
if [ $i -eq $j ]; then echo YES; else echo NO; fi
# YES
# YES
# YES
Bash
Copy
i="hello world"
j="hello my friend"
if [ "$i" = "$j" ]; then echo YES; else echo NO; fi
# NO
if [ $i = $j ]; then echo YES; else echo NO; fi
# -bash: [: too many arguments
# NO
if [ $i -eq $j ]; then echo YES; else echo NO; fi
# -bash: [: too many arguments
# NO
2 Cmd[ | ]
Bash
Copy
set my_name=John Smith&rem
IF "%my_name%"=="John Smith" ECHO my_name is John Smith
Bash
Copy
set my_name="John Smith"
IF %my_name%=="John Smith" ECHO my_name is "John Smith"
3 C#[ | ]
C#
Copy
int i = 1;
int j = 1;
if( i==j ) Console.WriteLine("i == j");
else Console.WriteLine("i != j");
// i == j
4 JavaScript[ | ]
JavaScript
Copy
Array.prototype.equals = function (array) {
if (!array) return false;
if (this.length != array.length) return false;
for (var i=0, l=this.length; i<l; i++) {
if (this[i] instanceof Array && array[i] instanceof Array) if (!this[i].equals(array[i])) return false;
else if (this[i] != array[i]) return false;
}
return true;
}
var a = ['a', 1, 'c'];
var b = ['a', 1, 'c'];
if( a.equals(b) ) alert('a = b');
5 PHP[ | ]
PHP
Copy
$i = 1;
$j = 2;
if( $i == $j ) echo "i == j";
else echo "i != j";
// i != j
6 Python[ | ]
Python
Copy
if 1 == 1:
print(True)
else:
print(False)
# True
Python
Copy
if 1 == 2:
print(True)
else:
print(False)
# False
7 Ruby[ | ]
Ruby
Copy
puts 2 == 2
# true
puts 2 == 3
# false
8 같이 보기[ | ]
편집자 Jmnote Jmnote bot
로그인하시면 댓글을 쓸 수 있습니다.