OILS / doc / warts.md View on Github | oilshell.org

70 lines, 45 significant
1---
2default_highlighter: oils-sh
3---
4
5YSH Language Warts
6==================
7
8This documents describes parts of the YSH language that may be surprising.
9
10All languages have warts, but most of them don't document them for you! Even a
11nice language like Python has surprising cases like `42,` and `f(x),` being a
121-tuple (because of the trailing comma).
13
14The goal of YSH is to remove the many warts of shell, documented at [Shell
15WTFs][wtfs]. Nonetheless it has some of its own.
16
17[wtfs]: https://github.com/oilshell/oil/wiki/Shell-WTFs
18
19<div id="toc">
20</div>
21
22## For Bash Compatibility
23
24### Two Left Parens Should be Separated By Space
25
26No:
27
28 if ((x + 1) < n) { # note ((
29 echo 'less'
30 }
31
32Yes:
33
34 if ( (x + 1) < n) { # add a space
35 echo 'less'
36 }
37
38This is because the `((` token is for bash arithmetic, which is disallowed in
39YSH.
40
41### Two Different Syntaxes For `Block` and `Expr` Literals
42
43Blocks look different in command vs expression mode:
44
45 cd /tmp { # command mode { }
46 echo $PWD
47 }
48 var myblock = ^(echo $PWD) # expression mode, lazy ^( )
49
50So do expressions:
51
52 myproc | where (age > 10) # command mode, lazy ( )
53 var myval = age > 10 # expression mode
54 var myexpr = ^[age > 10] # expression mode, lazy ^[ ]
55
56It would have been nicer if they were consistent, but shell is already
57inconsistent with `$(echo hi)` and `{ echo hi; }`.
58
59There is consistency in other directions:
60
61- `^(echo $PWD)` is consistent with shell's eagerly evaluated `$(echo $PWD)`.
62- `^[42 + f(x)]` is consistent with expression sub `$[42 + f(x)]`.
63
64Most users won't see these literal forms very much. They're more useful for
65testing and frameworks rather than simple scripts/applications.
66
67## Related
68
69- The doc on [compatibility quirks](quirks.html) relates to the OSH language.
70