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

How to compare strings in ifs? #6

Closed
richq opened this issue Mar 9, 2015 · 2 comments
Closed

How to compare strings in ifs? #6

richq opened this issue Mar 9, 2015 · 2 comments

Comments

@richq
Copy link
Contributor

richq commented Mar 9, 2015

When using if, bish seems to always uses -eq for string comparisons. This makes it impossible (?) to compare strings. I wanted to write a "direxists" that made sure the dir arg wasn't empty, but couldn't do it:

def direxists(dir) {
    if (dir == "") {
    return false;
    }
    @(test -d $dir);
    return success();
}

produces:

function bish_direxists () {
    if [[ $1 -eq "" ]]; then
        echo 0; exit;
    fi;
    test -d $1;
    echo $(bish_success); exit;
}

But this gives an error: line 7: [[: /dirname: syntax error: operand expected (error token is "/dirname"). Line 7 is the if with -eq on it.

@tdenniston
Copy link
Owner

This is an issue with code generation. Currently it always emits "-eq" for "==" because it does not check the type of the operands. Should be fairly straightforward to fix.

@tdenniston
Copy link
Owner

Should be fixed with b40db23. Thanks for reporting the issue!

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