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