0

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.

Cyrus
  • 84,225
  • 14
  • 89
  • 153
manners
  • 169
  • 1
  • 2
  • 10
  • variables does not expand within single quotes. So a literal `$1` will not match anything except for itself... Paste your script at https://shellcheck.net for validation. – Jetchisel May 12 '21 at 18:18
  • See: [Difference between single and double quotes in bash](http://stackoverflow.com/q/6697753/3776858) – Cyrus May 12 '21 at 18:20

0 Answers0