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

List contains returns true for checking if 2 exists in a list inserted with "2" #18

Closed
1sand0s opened this issue Apr 16, 2024 · 2 comments

Comments

@1sand0s
Copy link
Member

1sand0s commented Apr 16, 2024

Minimum working example

#!/bin/bash                                                                                         
. src/util/list.sh

lst=$(List)
$lst add 1
$lst add 3
$lst add "2"
$lst contains 2
echo $? # returns 0

This line essentially always does string compare which is true even when comparing "2" with 2.

if [ "${el}" = "${val}" ]; then 
	return $TRUE
fi
@gliga
Copy link
Member

gliga commented Apr 23, 2024

Thanks for the comment.

That example looks like something I would expect to see in bash. Everything is string in a way; there is really no difference between "2" and 2 when used in bash line, like you did.

$lst add "2"

is no diff from

$lst add 2

Here is also more "native" bash example.

#!/bin/bash                                                                                                                                                                                   

x=2
z="2"

if [ ${x} = "${z}" ]; then
        echo "same"
fi

What do you expect to see as the result in this case?

@gliga
Copy link
Member

gliga commented Apr 26, 2024

Closing based on the comment above and in-person agreement.

@gliga gliga closed this as completed Apr 26, 2024
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

2 participants