mercredi 12 mai 2021

Bash string using string comparison operator working the wrong way - opposite to expected result

This is my bash script:

#!/bin/bash
if [[ '$1' == 'movie' ]]
then
 echo 'true'
else
 echo 'false'
fi

But if I run it like this:

./bash.sh movie

It keep saying false.

Same if I write the code like this:

#!/bin/bash
if [ '$1' = 'movie' ]
then
 echo 'true'
else
 echo 'false'
fi

But if I do this:

#!/bin/bash
if [ '$1' != 'movie' ]
then
 echo 'true'
else
 echo 'false'
fi

It says True!!!!

Help me.

Aucun commentaire:

Enregistrer un commentaire