OILS / doc / ref / toc-ysh.md View on Github | oilshell.org

368 lines, 323 significant
1---
2title: YSH Table of Contents
3all_docs_url: ..
4css_files: ../../web/base.css ../../web/manual.css ../../web/ref-index.css
5preserve_anchor_case: yes
6---
7
8<div class="doc-ref-header">
9
10[Oils Reference](index.html) &mdash;
11[OSH](toc-osh.html) | **YSH Table of Contents** | [Data Notation](toc-data.html)
12
13</div>
14
15[YSH]($xref) is shell with a familiar syntax, JSON-like data structures, good
16error handling, and more.
17
18<!--
19<div class="custom-toc">
20
21[type-method](#type-method) &nbsp;
22[builtin-func](#builtin-func) &nbsp;
23[builtin-cmd](#builtin-cmd) &nbsp;
24[front-end](#front-end) &nbsp;
25[cmd-lang](#cmd-lang) &nbsp;
26[ysh-cmd](#ysh-cmd) &nbsp;
27[expr-lang](#expr-lang) &nbsp;
28[word-lang](#word-lang) &nbsp;
29[mini-lang](#mini-lang) &nbsp;
30[option](#option) &nbsp;
31[special-var](#special-var) &nbsp;
32[plugin](#plugin)
33
34</div>
35-->
36
37<h2 id="type-method">
38 Types and Methods <a class="group-link" href="chap-type-method.html">type-method</a>
39</h2>
40
41```chapter-links-type-method
42 [Atom Types] Null Bool
43 [Number Types] Int Float
44 [Str] X find() replace()
45 trim() trimStart() trimEnd()
46 startsWith() endsWith()
47 upper() lower()
48 search() leftMatch()
49 [List] List/append() pop() extend() indexOf()
50 X insert() X remove() reverse() X clear()
51 [Dict] erase() X clear() X Dict/append()
52 [Range]
53 [Eggex]
54 [Match] group() start() end()
55 X groups() X groupDict()
56 [Place] setValue()
57 [Code Types] Command CommandFrag
58 Expr ExprFrag
59 BuiltinFunc BoundFunc
60 Frame
61X [Func] name() location() toJson()
62X [Proc] name() location() toJson()
63 [IO] stdin evalExpr()
64 eval() evalToDict() captureStdout()
65 promptVal()
66 X time() X strftime() X glob()
67 [Obj] __invoke__ X __call__ __index__ X __str__
68 [VM] X getFrame()
69```
70
71<h2 id="builtin-func">
72 Builtin Functions <a class="group-link" href="chap-builtin-func.html">builtin-func</a>
73</h2>
74
75```chapter-links-builtin-func
76 [Values] len() func/type()
77 [Conversions] bool() int() float()
78 str() list() dict()
79 X runes() X encodeRunes()
80 X bytes() X encodeBytes()
81 [Str] X strcmp() X split() shSplit()
82 [List] join()
83 [Dict] keys() values() get()
84 [Float] floatsEqual() X isinf() X isnan()
85 [Obj] Object() prototype() propView()
86 get()
87 [Word] glob() maybe()
88 [Serialize] toJson() fromJson()
89 toJson8() fromJson8()
90X [J8 Decode] J8.Bool() J8.Int() ...
91 [Pattern] _group() _start() _end()
92 [Introspection] id()
93 shvarGet() getVar() setVar()
94 parseCommand() X parseExpr() X bindFrame()
95 [Hay Config] parseHay() evalHay()
96X [Hashing] sha1dc() sha256()
97```
98
99<!-- ideas
100X [Codecs] quoteUrl() quoteHtml() quoteSh() quoteC()
101 quoteMake() quoteNinja()
102X [Wok] _field()
103-->
104
105<h2 id="builtin-cmd">
106 Builtin Commands <a class="group-link" href="chap-builtin-cmd.html">builtin-cmd</a>
107</h2>
108
109<!-- linkify_stop_col is 42 -->
110
111```chapter-links-builtin-cmd_42
112 [Memory] cmd/append Add elements to end of array
113 pp value proc test_
114 asdl_ cell_ X gc-stats_
115 [Handle Errors] error error 'failed' (status=2)
116 try Run with errexit, set _error
117 failed Test if _error.code !== 0
118 boolstatus Enforce 0 or 1 exit status
119 assert assert [42 === f(x)]
120 [Shell State] ysh-cd ysh-shopt compatible, and takes a block
121 shvar Temporary modify global settings
122 ctx Share and update a temporary "context"
123 push-registers Save registers like $?, PIPESTATUS
124 [Introspection] runproc Run a proc; use as main entry point
125 X extern Run an external command, with an ENV
126 X invoke Control which "invokables" are run
127 [Modules]
128 source-guard guard against duplicate 'source'
129 is-main false when sourcing a file
130 use create a module Obj from a source file
131 [I/O] ysh-read flags --all, -0
132 ysh-echo no -e -n with simple_echo
133 ysh-test --file --true etc.
134 write Like echo, with --, --sep, --end
135 fork forkwait Replace & and (), and takes a block
136 fopen Open multiple streams, takes a block
137 [Hay Config] hay haynode For DSLs and config files
138 [Completion] compadjust compexport
139 [Data Formats] json read write
140 json8 read write
141```
142
143<h2 id="stdlib">
144 Standard Library<a class="group-link" href="chap-stdlib.html">stdlib</a>
145</h2>
146
147```chapter-links-stdlib
148 [math] abs() max() min() X round()
149 sum()
150 [list] all() any() repeat()
151 [yblocks] yb-capture yb-capture-2
152 [args] parser flag arg rest
153 parseArgs()
154```
155
156<!-- linkify_stop_col is 42 -->
157
158Design for streams and tables (awk/xargs/dplyr):
159
160```chapter-links-stdlib_42
161X [Lines] slurp-by combine adjacent lines into cells
162X [Awk] each-line --j8 --max-jobs (Str, Template, Block)
163 each-row --max-jobs (Str, Template, Block)
164 each-word xargs-like splitting, similar to IFS too
165 split-by (str=\n, ifs=':', pattern=/s+/)
166 if-split-by only lines that match
167 chop alias for split-by (pattern=/s+/)
168 must-match (/ <capture d+> </capture w+> /)
169 if-match only lines that match
170X [Table Create] table def &place or print TSV8
171 table parse --by-row --by-col (&place), TSV or TSV8
172 table/cols cols name age, or name:Str age:Int
173 types type Str Int
174 attr attr units - secs
175 row emit row
176 table cat concatenate TSV8
177 table align to ssv8
178 table tabify to tsv8 (similar to table parse)
179 table header cols = :|name age|, types = :|Str Int|, ...
180 table slice e.g. slice (1, -1) slice (5, 7)
181 table to-tsv lose type info, and error on \t in cells
182X [Table Ops] where subset of rows; dplyr filter()
183 pick subset of columns ('select' taken by shell)
184 mutate [average = count / sum]
185 transmute drop columns that are used
186 rename (bytes='bytes', path='filename')
187 group-by add a column with a group ID [ext]
188 sort-by sort by columns; dplyr arrange() [ext]
189 summary count/sum, histogram, any/all, reduce, ...
190```
191
192<!--
193Naming ideas:
194
195X [External Lang] BEGIN END when (awk)
196 rule (make) each (xargs) fs (find)
197-->
198
199<h2 id="front-end">
200 Front End <a class="group-link" href="chap-front-end.html">front-end</a>
201</h2>
202
203```chapter-links-front-end
204 [Usage] oils-usage ysh-usage
205 [Lexing] ascii-whitespace [ \t\r\n]
206 doc-comment ### multiline-command ...
207 [Tools] cat-em
208```
209
210<h2 id="cmd-lang">
211 Command Language <a class="group-link" href="chap-cmd-lang.html">cmd-lang</a>
212</h2>
213
214<!-- linkify_stop_col is 33 -->
215
216```chapter-links-cmd-lang_33
217 [Redirect] ysh-here-str read <<< '''
218 [YSH Simple] typed-arg json write (x)
219 lazy-expr-arg assert [42 === x]
220 block-arg cd /tmp { echo $PWD }; cd /tmp (; ; blockexpr)
221 [YSH Cond] ysh-case case (x) { *.py { echo 'python' } }
222 ysh-if if (x > 0) { echo }
223 [YSH Iter] ysh-for for i, item in (mylist) { echo }
224 ysh-while while (x > 0) { echo }
225```
226
227<h2 id="ysh-cmd">
228 YSH Command Language Keywords <a class="group-link" href="chap-ysh-cmd.html">ysh-cmd</a>
229</h2>
230
231```chapter-links-ysh-cmd_33
232 [Assignment] const var Declare variables
233 setvar setvar a[i] = 42
234 setglobal setglobal d.key = 'foo'
235 [Expression] equal = = 1 + 2*3
236 call call mylist->append(42)
237 [Definitions] proc proc p (s, ...rest) {
238 typed proc p (; typed, ...rest; n=0; b) {
239 func func f(x; opt1, opt2) { return (x + 1) }
240 ysh-return return (myexpr)
241```
242
243<h2 id="expr-lang">
244 Expression Language and Assignments <a class="group-link" href="chap-expr-lang.html">expr-lang</a>
245</h2>
246
247<!-- linkify_stop_col is 33 -->
248
249```chapter-links-expr-lang_33
250 [Assignment] assign =
251 aug-assign += -= *= /= **= //= %=
252 &= |= ^= <<= >>=
253 [Literals] atom-literal true false null
254 int-literal 42 65_536 0xFF 0o755 0b10
255 float-lit 3.14 1.5e-10
256 char-literal \\ \t \" \y00 \u{3bc}
257 X num-suffix 42 K Ki M Mi G Gi T Ti / ms us
258 ysh-string "x is $x" $"x is $x" r'[a-z]\n'
259 u'line\n' b'byte \yff'
260 triple-quoted """ $""" r''' u''' b'''
261 str-template ^"$a and $b" for Str::replace()
262 list-literal ['one', 'two', 3] :| unquoted words |
263 dict-literal {name: 'bob'} {a, b}
264 range 1 ..< n 1 ..= n
265 block-expr ^(echo $PWD)
266 expr-literal ^[1 + 2*3]
267 X expr-sub $[myobj]
268 X expr-splice @[myobj]
269 [Operators] op-precedence Like Python
270 concat s1 ++ s2, L1 ++ L2
271 ysh-equals === !== ~== is, is not
272 ysh-in in, not in
273 ysh-compare < <= > >= (numbers only)
274 ysh-logical not and or
275 ysh-arith + - * / // % **
276 ysh-bitwise ~ & | ^ << >>
277 ysh-ternary '+' if x >= 0 else '-'
278 ysh-index s[0] mylist[3] mydict['key']
279 ysh-attr mydict.key mystr.startsWith('x')
280 ysh-slice a[1:-1] s[1:-1]
281 func-call f(x, y; ...named)
282 thin-arrow mylist->pop()
283 fat-arrow mylist => join() => upper()
284 match-ops ~ !~ ~~ !~~
285 [Eggex] re-literal / d+ ; re-flags ; ERE /
286 re-primitive %zero 'sq'
287 class-literal [c a-z 'abc' @str_var \\ \xFF \u{3bc}]
288 named-class dot digit space word d s w
289 re-repeat d? d* d+ d{3} d{2,4}
290 re-compound seq1 seq2 alt1|alt2 (expr1 expr2)
291 re-capture <capture d+ as name: int>
292 re-splice Subpattern @subpattern
293 re-flags reg_icase reg_newline
294 X re-multiline ///
295```
296
297<h2 id="word-lang">
298 Word Language <a class="group-link" href="chap-word-lang.html">word-lang</a>
299</h2>
300
301<!-- linkify_stop_col is 33 -->
302
303```chapter-links-word-lang_33
304 [Quotes] ysh-string "x is $x" $"x is $x" r'[a-z]\n'
305 u'line\n' b'byte \yff'
306 triple-quoted """ $""" r''' u''' b'''
307 X tagged-str "<span id=$x>"html
308 [Substitutions] expr-sub echo $[42 + a[i]]
309 expr-splice echo @[split(x)]
310 var-splice @myarray @ARGV
311 command-sub @(cat my-j8-lines.txt)
312 [Formatting] X ysh-printf ${x %.3f}
313 X ysh-format ${x|html}
314```
315
316<h2 id="mini-lang">
317 Other Mini Languages <a class="group-link" href="chap-mini-lang.html">mini-lang</a>
318</h2>
319
320<!-- linkify_stop_col is 33 -->
321
322```chapter-links-mini-lang_33
323 [Patterns] glob-pat *.py
324 [Other Sublang] braces {alice,bob}@example.com
325```
326
327<h2 id="option">
328 Global Shell Options <a class="group-link" href="chap-option.html">option</a>
329</h2>
330
331```chapter-links-option
332 [Groups] strict:all ysh:upgrade ysh:all
333 [YSH Details] opts-redefine opts-internal
334```
335
336<h2 id="special-var">
337 Special Variables <a class="group-link" href="chap-special-var.html">special-var</a>
338</h2>
339
340```chapter-links-special-var
341 [YSH Vars] ARGV X ENV X _ESCAPE
342 _this_dir
343 [YSH Status] _error
344 _pipeline_status _process_sub_status
345 [YSH Tracing] SHX_indent SHX_punct SHX_pid_str
346 [YSH read] _reply
347 [History] YSH_HISTFILE
348 [Oils VM] OILS_VERSION
349 OILS_GC_THRESHOLD OILS_GC_ON_EXIT
350 OILS_GC_STATS OILS_GC_STATS_FD
351 LIB_YSH
352 [Float] NAN INFINITY
353 [Module] __provide__
354```
355
356<!-- ideas
357 [Module] __rear__ - for evalToDict()?
358X [Wok] _filename _line _line_num
359X [Builtin Sub] _buffer
360-->
361
362<h2 id="plugin">
363 Plugins and Hooks <a class="group-link" href="chap-plugin.html">plugin</a>
364</h2>
365
366```chapter-links-plugin
367 [YSH] renderPrompt()
368```