Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: if (()){}else{} documented?



Hi David,

> e.g. this only works as a single line (is that true?)
> if (( $1 == 4 )) { echo good } else { echo bad }

i'm not sure what a "single line" is. the "else" keyword should
not appear at the very begin of an expression but all the rest is ok.

meaning those are correct

     if (( $1 == 4 )) { echo good } else { echo bad }

     if (( $1 == 4 )) {
         echo good
     } else {
         echo bad
     }

this is not

     if (( $1 == 4 )) {
         echo good
     }
     else {
         echo bad
     }

> just wondered where I could read up on this?

all the following examples works fine there. i'm even surprised about
this one

> joe(){ [[ $1 > 4 ]] && echo big || echo small }

this is a math expression so i would have written

joe(){ (( $1 > 4 )) && echo big || echo small }

regards
marc




Messages sorted by: Reverse Date, Date, Thread, Author