| 1 | #### not, and, or |
| 2 | |
| 3 | var a = not true |
| 4 | echo $a |
| 5 | var b = true and false |
| 6 | echo $b |
| 7 | var c = true or false |
| 8 | echo $c |
| 9 | |
| 10 | ## STDOUT: |
| 11 | false |
| 12 | false |
| 13 | true |
| 14 | ## END |
| 15 | |
| 16 | |
| 17 | #### and-or chains for typed data |
| 18 | |
| 19 | python2 -c 'print(None or "s")' |
| 20 | python2 -c 'print(None and "s")' |
| 21 | |
| 22 | python2 -c 'print("x" or "y")' |
| 23 | python2 -c 'print("x" and "y")' |
| 24 | |
| 25 | python2 -c 'print("" or "y")' |
| 26 | python2 -c 'print("" and "y")' |
| 27 | |
| 28 | python2 -c 'print(42 or 0)' |
| 29 | python2 -c 'print(42 and 0)' |
| 30 | |
| 31 | python2 -c 'print(0 or 42)' |
| 32 | python2 -c 'print(0 and 42)' |
| 33 | |
| 34 | python2 -c 'print(0.0 or 0.5)' |
| 35 | python2 -c 'print(0.0 and 0.5)' |
| 36 | |
| 37 | python2 -c 'print(["a"] or [])' |
| 38 | python2 -c 'print(["a"] and [])' |
| 39 | |
| 40 | python2 -c 'print({"d": 1} or {})' |
| 41 | python2 -c 'print({"d": 1} and {})' |
| 42 | |
| 43 | python2 -c 'print(0 or 0.0 or False or [] or {} or "OR")' |
| 44 | python2 -c 'print(1 and 1.0 and True and [5] and {"d":1} and "AND")' |
| 45 | |
| 46 | echo --- |
| 47 | |
| 48 | json write (null or "s") |
| 49 | json write (null and "s") |
| 50 | |
| 51 | echo $["x" or "y"] |
| 52 | echo $["x" and "y"] |
| 53 | |
| 54 | echo $["" or "y"] |
| 55 | echo $["" and "y"] |
| 56 | |
| 57 | echo $[42 or 0] |
| 58 | echo $[42 and 0] |
| 59 | |
| 60 | echo $[0 or 42] |
| 61 | echo $[0 and 42] |
| 62 | |
| 63 | echo $[0.0 or 0.5] |
| 64 | echo $[0.0 and 0.5] |
| 65 | |
| 66 | json write --pretty=false (["a"] or []) |
| 67 | json write --pretty=false (["a"] and []) |
| 68 | |
| 69 | json write --pretty=false ({"d": 1} or {}) |
| 70 | json write --pretty=false ({"d": 1} and {}) |
| 71 | |
| 72 | echo $[0 or 0.0 or false or [] or {} or "OR"] |
| 73 | echo $[1 and 1.0 and true and [5] and {"d":1} and "AND"] |
| 74 | |
| 75 | declare -a array=(1 2 3) |
| 76 | json write --pretty=false (array or 'yy') |
| 77 | |
| 78 | declare -A assoc=([k]=v) |
| 79 | json write --pretty=false (assoc or 'zz') |
| 80 | |
| 81 | ## STDOUT: |
| 82 | s |
| 83 | None |
| 84 | x |
| 85 | y |
| 86 | y |
| 87 | |
| 88 | 42 |
| 89 | 0 |
| 90 | 42 |
| 91 | 0 |
| 92 | 0.5 |
| 93 | 0.0 |
| 94 | ['a'] |
| 95 | [] |
| 96 | {'d': 1} |
| 97 | {} |
| 98 | OR |
| 99 | AND |
| 100 | --- |
| 101 | "s" |
| 102 | null |
| 103 | x |
| 104 | y |
| 105 | y |
| 106 | |
| 107 | 42 |
| 108 | 0 |
| 109 | 42 |
| 110 | 0 |
| 111 | 0.5 |
| 112 | 0.0 |
| 113 | ["a"] |
| 114 | [] |
| 115 | {"d":1} |
| 116 | {} |
| 117 | OR |
| 118 | AND |
| 119 | ["1","2","3"] |
| 120 | {"k":"v"} |
| 121 | ## END |
| 122 | |
| 123 | #### x if b else y |
| 124 | var b = true |
| 125 | var i = 42 |
| 126 | var t = i+1 if b else i-1 |
| 127 | echo $t |
| 128 | var f = i+1 if false else i-1 |
| 129 | echo $f |
| 130 | ## STDOUT: |
| 131 | 43 |
| 132 | 41 |
| 133 | ## END |
| 134 |