linux - [Solved-5 Solutions] How to compare two string variables in an 'if' statement in Bash - ubuntu - red hat - debian - linux server - linux pc
Linux - Problem :
How to compare two string variables in an 'if' statement in Bash ?
Linux - Solution 1:
For string comparison, use:
For the a contains b, use:
Ensure to add spaces between the symbols:
Linux - Solution 2:
You need spaces:
Linux - Solution 3:
You should be careful to leave a space between the sign of '[' and double quotes where the variable contains this:
The ^s show the blank spaces you need to leave.
Linux - Solution 4:
Notice the white space between the openning/closing brackets and the variables and also the white spaces wrapping the '=' sign.
Also, be careful of your script header. It's not the same thing whether you use
or
Linux - Solution 5:
Without the double quotes and with only one equals.