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?
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.
Comments