Home > Mobile >  Shell/Bash - equality check between strings returns 1 on match
Shell/Bash - equality check between strings returns 1 on match

Time:11-07

I'm trying to compare output of a cli command "successful" with simple test = $? but getting 1 even though values match. I did the same on hard-coded example and works fine.

Should the variable that stores cli's output be in different wrapping?

#ri status:
ri_status=`aws dms describe-connections --filter Name=replication-instance-arn,Values=$ri_arn --query=Connections[0].Status --region us-east-1`

#returns "successful"
echo $ri_status

#this returns 0
test "successful" = "successful"
echo $?

#this returns 1
test $ri_status = "successful"
echo $?

CodePudding user response:

Fixed with '

http://www.gnu.org/savannah-checkouts/gnu/bash/manual/bash.html#Quoting

3.1.2.2 Single Quotes

Enclosing characters in single quotes (‘'’) preserves the literal value of each character within the quotes. A single quote may not occur between single quotes, even when preceded by a backslash.

test $ri_status = '"successful"'
  • Related