1

I have the following script

#!/bin/bash   
if [ $1=="1" ]
then
    echo $1
fi

Whenever I run ./myscript.sh 0 it still prints "0". I am not sure why? It prints whatever I type in because the if executes. What would I need to change?

user1357015
  • 10,429
  • 19
  • 62
  • 104

1 Answers1

2

Add proper spaces, i.e. before and after == inside if condition

#!/bin/bash   

if [ $1 == "1" ] 
then
    echo $1
fi
shizhen
  • 11,455
  • 9
  • 49
  • 81