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

let not implemented #622

Open
jyn514 opened this issue Mar 4, 2020 · 1 comment
Open

let not implemented #622

jyn514 opened this issue Mar 4, 2020 · 1 comment

Comments

@jyn514
Copy link
Contributor

jyn514 commented Mar 4, 2020

I found this because I ran into an infinite loop in bash_completion (the original, not the osh fork)!

The original code was

    local exclude flag i OPTIND=1
    # lots more code
    let "OPTIND += 1"

It looks like this should be the same as $(( )) but without then evaluating the result?

$ help let
let: let arg [arg ...]
    Evaluate arithmetic expressions.
    
    Evaluate each ARG as an arithmetic expression.  Evaluation is done in
    fixed-width integers with no check for overflow, though division by 0
    is trapped and flagged as an error.  The following list of operators is
    grouped into levels of equal-precedence operators.  The levels are listed
    in order of decreasing precedence.
    
    	id++, id--	variable post-increment, post-decrement
    	++id, --id	variable pre-increment, pre-decrement
    	-, +		unary minus, plus
    	!, ~		logical and bitwise negation
    	**		exponentiation
    	*, /, %		multiplication, division, remainder
    	+, -		addition, subtraction
    	<<, >>		left and right bitwise shifts
    	<=, >=, <, >	comparison
    	==, !=		equality, inequality
    	&		bitwise AND
    	^		bitwise XOR
    	|		bitwise OR
    	&&		logical AND
    	||		logical OR
    	expr ? expr : expr
    			conditional operator
    	=, *=, /=, %=,
    	+=, -=, <<=, >>=,
    	&=, ^=, |=	assignment
    
    Shell variables are allowed as operands.  The name of the variable
    is replaced by its value (coerced to a fixed-width integer) within
    an expression.  The variable need not have its integer attribute
    turned on to be used in an expression.
    
    Operators are evaluated in order of precedence.  Sub-expressions in
    parentheses are evaluated first and may override the precedence
    rules above.
    
    Exit Status:
    If the last ARG evaluates to 0, let returns 1; let returns 0 otherwise.
@andychu
Copy link
Contributor

andychu commented Mar 4, 2020

Yup let is just a synonym for (( LHS = expr )) ... It's low priority since the the rewrite is trivial, and so far I only ran into it in bash-completion. But it would be pretty easy to implement in any case.

over time we can adjust this: https://github.com/oilshell/oil/wiki/What-Is-Expected-to-Run-Under-OSH

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

No branches or pull requests

2 participants