2

Everytime I run my script the following if statement gives me the error;

script.sh: [Error==Error]: not found

or

script.sh: [Error==-2]: not found

if ["$P1"=="$P2"];then
            echo $name
fi

I've tried other versions

    if ["$P1"=="$P2"]
            then
            echo $name
    fi

and

    if [[ "$P1" == "$P2" ]]
            then
            echo $name
fi

P1="Error"
P2="$(sed -n '1p' somefile.txt)"

somefile.txt might contain a number or a string

1
  • Take a look at shellcheck.net Commented Nov 1, 2014 at 9:51

1 Answer 1

9

Spaces are significant. Use:

if [ "$P1" = "$P2" ]

What went wrong

When the shell sees ["$P1"=="$P2"], it interprets it as a single word and looks for a command that matches that word. Since no such command exists, you get the not found error message.

2
  • Did exact same thing and got an ` [:` unexpected operator error. Commented Nov 1, 2014 at 3:15
  • 1
    Had to use = instead of ==. works now. Thanks Commented Nov 1, 2014 at 3:17

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.