Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to compare user input in unix [duplicate]

Tags:

bash

shell

unix

So I'm writing a simple script and I cant seem to get it to work. It throws a error at the if statement.

#!/bin/bash
echo "Whats your name ?"
read NAME

if [$NAME == "SSJ" ]
then
  echo "Welcome back SSJ"
fi
like image 647
Sandeep Johal Avatar asked Dec 02 '25 14:12

Sandeep Johal


1 Answers

Do it like this:

#!/bin/bash
echo "Whats your name ?"
read name

if [ "$name" = "SSJ" ]
then
  echo "Welcome back SSJ"
fi
like image 72
midori Avatar answered Dec 05 '25 12:12

midori



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!