0

I've been reading through StackExchange posts on scripting and none of the things that I have tried are working as I would expect.

Also this is my 1st shell script.

# Script File Begin
echo "Enter yes | no"
read uInput

if ["$uInput" != "n"]; then
  echo "Yes"
fi

The issue is when I run this no matter how I try the if condition I keep getting line 5: n: command not found

I have tried different iterations such as

[["$uInput" != "n*"]]
[["$uInput" != n*]]
[[$uInput != n*]]
["$uInput" != "n*"]
["$uInput" != n*]
[$uInput != "n*"]
[$uInput != n*]

But they all tell me the same thing line 5: n: command not found.

What am I missing?

Jahid
  • 21,542
  • 10
  • 90
  • 108
edjm
  • 4,830
  • 7
  • 36
  • 65

1 Answers1

1

Spaces in Bash are crucial not optional. Change the if statement to:

if [ "$uInput" != "n" ]; then


If you are wondering why? see this:

Why should be there a space after '[' and before ']' in the Bash Script

Community
  • 1
  • 1
Jahid
  • 21,542
  • 10
  • 90
  • 108
  • If you are posting this as answer at least explain why spaces are required. – 123 Jun 18 '15 at 13:03
  • Thank you both. I'm big on always taking out white-spaces. Guess I'll have to stop doing that. – edjm Jun 18 '15 at 13:07
  • 1
    @User112638726 done... – Jahid Jun 18 '15 at 13:50
  • Also for additional information [[ $uInput != n* ]] will check for pattern matching anything with n in the front (n, no, nope, none, nada etc.) – edjm Jun 18 '15 at 14:53