Exec vs source error on ==

nobe4

I run a strange error with the following code:

#!/usr/bin/env bash

a="a"
b="a"

if [ "$a" == "$b" ]
then
  echo "Eq"
fi

chmod u+x script.sh

Then executing the file will display Eq:

$ ./script.sh
Eq

But sourcing it results in an error:

$ source script.sh
script.sh:6: = not found

Do you know what can cause this error?

choroba

When sourcing the script, your current shell executes the commands. In zsh, you must use a single = in comparison.

$ echo '[ a == a ]' | zsh
zsh: = not found
exit code: 1
$ echo '[ a = a ]' | zsh
$

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related