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