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

Braiam
  • 35,991
pyler
  • 175

1 Answers1

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.

John1024
  • 74,655