#String checks operator and techniques
str1="ishant"
str2="gaurav"
str3=""
# to check if two string are equal, command should return 1
[ "$str1" = "$str2" ]
echo $?
# to check if two string are equal, command should return 1
[ "$str1" != "$str2" ]
echo $?
# to check if str1 size is greater than 0
[ -n "$str1" ]
echo $?
# to check if str3 is equal to 0
[ -z "$str3" ]
echo $?
str1="ishant"
str2="gaurav"
str3=""
# to check if two string are equal, command should return 1
[ "$str1" = "$str2" ]
echo $?
# to check if two string are equal, command should return 1
[ "$str1" != "$str2" ]
echo $?
# to check if str1 size is greater than 0
[ -n "$str1" ]
echo $?
# to check if str3 is equal to 0
[ -z "$str3" ]
echo $?
The command $? gives the exit status. hence in all of the above cases the exit status is 0.You will not get 1 as exit status as long as the previous commands are executed succesfully
ReplyDelete