OILS / doc / ref / chap-word-lang.md View on Github | oilshell.org

130 lines, 77 significant
1---
2in_progress: yes
3body_css_class: width40 help-body
4default_highlighter: oils-sh
5preserve_anchor_case: yes
6---
7
8Word Language
9===
10
11This chapter in the [Oils Reference](index.html) describes the word language
12for OSH and YSH.
13
14<div id="toc">
15</div>
16
17<h2 id="expression">Expressions to Words</h2>
18
19### expr-sub
20
21### expr-splice
22
23### var-splice
24
25<h2 id="formatting">Formatting Typed Data as Strings</h2>
26
27### ysh-printf
28
29### ysh-format
30
31
32## Quotes
33
34### osh-string
35
36- Single quotes
37- Double Quotes
38- C-style strings: `$'\n'`
39
40TODO: elaborate
41
42### ysh-string
43
44YSH strings in the word language are the same as in the expression language.
45
46See [ysh-string in chap-expr-lang](chap-expr-lang.html#ysh-string).
47
48### triple-quoted
49
50Triple-quoted in the word language are the same as in the expression language.
51
52See [triple-quoted in chap-expr-lang](chap-expr-lang.html#triple-quoted).
53
54### tagged-str
55
56Not done.
57
58## Substitutions
59
60### command-sub
61
62Executes a command and captures its stdout.
63
64OSH has shell-compatible command sub like `$(echo hi)`. If a trailing newline
65is returned, it's removed:
66
67 $ hostname
68 example.com
69
70 $ echo "/tmp/$(hostname)"
71 /tmp/example.com
72
73YSH has spliced command subs, enabled by `shopt --set parse_at`. The reuslt is
74a **List** of strings, rather than a single string.
75
76 $ write -- @(echo foo; echo 'with spaces')
77 foo
78 with-spaces
79
80The command's stdout parsed as the "J8 Lines" format, where each line is
81either:
82
831. An unquoted string, which must be valid UTF-8. Whitespace is allowed, but
84 not other ASCII control chars.
852. A quoted J8 string (JSON style `""` or J8-style `b'' u'' ''`)
863. An **ignored** empty line
87
88See [J8 Notation](../j8-notation.html) for more details.
89
90### var-sub
91
92Evaluates to the value of a variable:
93
94 $ x=X
95 $ echo $x ${x}
96 X X
97
98### arith-sub
99
100Shell has C-style arithmetic:
101
102 $ echo $(( 1 + 2*3 ))
103 7
104
105### tilde-sub
106
107Used as a shortcut for a user's home directory:
108
109 ~/src # my home dir
110 ~bob/src # user bob's home dir
111
112## Var Ops
113
114### op-test
115
116### op-strip
117
118### op-replace
119
120### op-index
121
122 ${a[i+1]}
123
124### op-slice
125
126### op-format
127
128${x@P} evaluates x as a prompt string, e.g. the string that would be printed if
129PS1=$x.
130