0

I'd like to compare an Output with an string. My script looks like this:

#!/bin/bash
DRBD=$(drbd-overview)
COMP=' 0:nfs-ha/0  Connected Secondary/Primary UpToDate/UpToDate'

DEBUG=1

if [ $DEBUG == "1" ];
then
  echo "Debug:"
  echo $COMP
  echo $DRBD
  echo "Debug-Ende"
fi

if [[ "x$DRBD" = "x$COMP" ]];
then
  RTRN='Check_OK'
else
  RTRN="$DRBD"
fi

echo "Return: $RTRN"

& bash -x script.sh looks like this:

bash -x scripts.sh
++ drbd-overview
+ DRBD=' 0:nfs-ha/0  Connected Secondary/Primary UpToDate/UpToDate '
+ COMP=' 0:nfs-ha/0  Connected Secondary/Primary UpToDate/UpToDate'
+ DEBUG=1
+ '[' 1 == 1 ']'
+ echo Debug:
Debug:
+ echo 0:nfs-ha/0 Connected Secondary/Primary UpToDate/UpToDate
0:nfs-ha/0 Connected Secondary/Primary UpToDate/UpToDate
+ echo 0:nfs-ha/0 Connected Secondary/Primary UpToDate/UpToDate
0:nfs-ha/0 Connected Secondary/Primary UpToDate/UpToDate
+ echo Debug-Ende
Debug-Ende
+ [[ x 0:nfs-ha/0  Connected Secondary/Primary UpToDate/UpToDate  = \x\ \0\:\n\f\s\-\h\a\/\0\ \ \C\o\n\n\e\c\t\e\d\ \S\e\c\o\n\d\a\r\y\/\P\r\i\m\a\r\y\ \U\p\T\o\D\a\t\e\/\U\p\T\o\D\a\t\e ]]
+ RTRN=' 0:nfs-ha/0  Connected Secondary/Primary UpToDate/UpToDate '
+ echo 'Return:  0:nfs-ha/0  Connected Secondary/Primary UpToDate/UpToDate '
Return:  0:nfs-ha/0  Connected Secondary/Primary UpToDate/UpToDate

what did I do wrong that $COMP is escaped within the bash statement?

1 Answer 1

1

The two strings are not identical. $DRBD has a space at the end while $COMP doesn't (you can see this in the trace output). This is why the comparison doesn't set RTRN to Check_OK.

1
  • how could I be that blind? - Thanks! Commented Feb 2, 2017 at 12:54

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.