Xaver
Xaver

Reputation: 11682

Equal is not equal in shell script

I'm using a shell script to deploy my plugins to the WordPress repo.

While this works in most cases some plugins fail. The problem is when the script checks for the version number and compare the readme.txt with the actual plugin file [Source].

Example output:

readme version: 0.5
plugin.php version: 0.5
Versions don't match. Exiting....

I can just remove the check but I would like to have just for its initial purpose.

So why is 0.5 != 0.5? is this a wrong type?

EDIT:

This is the part of the script

# Check version in readme.txt is the same as plugin file
NEWVERSION1=`grep "^Stable tag" $GITPATH/readme.txt | awk -F' ' '{print $3}'`
echo "readme version: $NEWVERSION1"
NEWVERSION2=`grep "^Version" $GITPATH/$MAINFILE | awk -F' ' '{print $2}'`
echo "$MAINFILE version: $NEWVERSION2"

if [ "$NEWVERSION1" != "$NEWVERSION2" ]; then echo "Versions don't match $NEWVERSION1 != $NEWVERSION2. Exiting...."; exit 1; fi

Update

When doing

if [ "$NEWVERSION1" != "$NEWVERSION2" ]; then echo "Versions don't match $NEWVERSION1# != $NEWVERSION2#. Exiting...."; exit 1; fi

i get as output

#. Exiting.... match 0.5# != 0.5

so the '#' is at the beginning.

Upvotes: 1

Views: 1078

Answers (1)

Karoly Horvath
Karoly Horvath

Reputation: 96266

#. Exiting.... match 0.5# != 0.5

Your second value contains a \r which will move the cursor to the beginning of the line, hence the output.

echo -e "abc\rd"   # dbc

Strip it with | tr -d '\r'.

Upvotes: 3

Related Questions