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
  • 11,168
  • 22
  • 66
  • 111

1 Answers1

2

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

#!/bin/bash   

if [ $1 == "1" ] 
then
    echo $1
fi
shizhen
  • 12,251
  • 9
  • 52
  • 88