Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Double equality used within single square brackets in build script #1273

Closed
bervel opened this issue Mar 22, 2024 · 1 comment
Closed

Double equality used within single square brackets in build script #1273

bervel opened this issue Mar 22, 2024 · 1 comment
Assignees

Comments

@bervel
Copy link

bervel commented Mar 22, 2024

I had to update the build script, replace double equality with single on line 57 to get it to run. Otherwise comparison of equal string variables containing the version "5.0.0" fails.

`if [ "${FILEBEAT_TEMPLATE_BRANCH}" == "${WAZUH_MASTER_VERSION}" ]; then'
changed to
'if [ "${FILEBEAT_TEMPLATE_BRANCH}" = "${WAZUH_MASTER_VERSION}" ]; then'

@davidcr01 davidcr01 self-assigned this Apr 15, 2024
@davidcr01
Copy link
Contributor

Hello.

In bash, = and == are synonyms. However, the = operator should be used with the test commando for POSIX compliance. Which shell are you using?

I tested this behavior in my machine and no difference was found:

The test, test.sh file:

set -x
FILEBEAT_TEMPLATE_BRANCH=5.0.0

WAZUH_MASTER_VERSION="$(curl -s https://raw.githubusercontent.com/wazuh/wazuh/master/src/VERSION | sed -e 's/v//g')"

echo "${WAZUH_MASTER_VERSION}"


if [ "${FILEBEAT_TEMPLATE_BRANCH}" = "${WAZUH_MASTER_VERSION}" ]; then
  echo "They're equal"
else
  echo "They're not equal"
fi

First execution, with == operator:

$ bash test.sh
+ FILEBEAT_TEMPLATE_BRANCH=5.0.0
++ curl -s https://raw.githubusercontent.com/wazuh/wazuh/master/src/VERSION
++ sed -e s/v//g
+ WAZUH_MASTER_VERSION=5.0.0
+ echo 5.0.0
5.0.0
+ '[' 5.0.0 == 5.0.0 ']'
+ echo 'They'\''re equal'
They're equal

Second execution, with = operator:

$ bash test.sh
+ FILEBEAT_TEMPLATE_BRANCH=5.0.0
++ curl -s https://raw.githubusercontent.com/wazuh/wazuh/master/src/VERSION
++ sed -e s/v//g
+ WAZUH_MASTER_VERSION=5.0.0
+ echo 5.0.0
5.0.0
+ '[' 5.0.0 = 5.0.0 ']'
+ echo 'They'\''re equal'
They're equal

Anyway, we will discuss this with the team and see if we need to change the operator or not.
Reference: https://www.gnu.org/software/bash/manual/html_node/Bash-Conditional-Expressions.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants