Bash – String Comparisons

Bash String Comparisons Use double equals ( == ) operator to compare strings inside square brackets []. Using this option you simply test if two given strings are equals or not inside bash shell scripts. Example Syntax: if [ “$str1” == “$str2” ] # True if equal if [ “$str1” != “$str2” ] # True if not equal Example: For example to compare two string are equal or not. if [ “hello” == “hello” ] ## True if [ “hello” == “hello1” ] ## False if [ “hello” != “hello”…

Read More

Bash – Numeric Comparisons

Bash Numeric Comparisons Under bash shell, you can directly compare numeric values using double parentheses like “((expression))”. Syntax: ((n1 > n2)) Example: Compare two values and check if one is greater than other value. Write below script in file.

Now execute this script using bash shell $ chmod +x ./ $ ./ True Bash – Numeric Comparisons Operators You can try with many more comparison operators in bash shell to compare two numeric values. ((n1 == n2)) ## n1 is equals to n2 ((n1 != n2)) ## n1…

Read More