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 | [Commands] simple-command
|
221 | ysh-prefix-binding
|
222 | semicolon ;
|
223 | [Redirects] ysh-here-str read <<< '''
|
224 | [YSH Simple] typed-arg json write (x)
|
225 | lazy-expr-arg assert [42 === x]
|
226 | block-arg cd /tmp { echo $PWD }; cd /tmp (; ; blockexpr)
|
227 | [YSH Cond] ysh-case case (x) { *.py { echo 'python' } }
|
228 | ysh-if if (x > 0) { echo }
|
229 | [YSH Iter] ysh-for for i, item in (mylist) { echo }
|
230 | ysh-while while (x > 0) { echo }
|
231 | ```
|
232 |
|
233 | <!-- TODO: move YSH command topics to the chapter below -->
|
234 |
|
235 | <h2 id="ysh-cmd">
|
236 | YSH Command Language Keywords <a class="group-link" href="chap-ysh-cmd.html">ysh-cmd</a>
|
237 | </h2>
|
238 |
|
239 | ```chapter-links-ysh-cmd_39
|
240 | [Assignment] const var Declare variables
|
241 | setvar setvar a[i] = 42
|
242 | setglobal setglobal d.key = 'foo'
|
243 | [Expression] equal = = 1 + 2*3
|
244 | call call mylist->append(42)
|
245 | [Definitions] proc proc p (s, ...rest) {
|
246 | typed proc p (; typed, ...rest; n=0; b) {
|
247 | func func f(x; opt1, opt2) { return (x + 1) }
|
248 | ysh-return return (myexpr)
|
249 | ```
|
250 |
|
251 | <h2 id="expr-lang">
|
252 | Expression Language and Assignments <a class="group-link" href="chap-expr-lang.html">expr-lang</a>
|
253 | </h2>
|
254 |
|
255 | <!-- linkify_stop_col is 33 -->
|
256 |
|
257 | ```chapter-links-expr-lang_33
|
258 | [Assignment] assign =
|
259 | aug-assign += -= *= /= **= //= %=
|
260 | &= |= ^= <<= >>=
|
261 | [Literals] atom-literal true false null
|
262 | int-literal 42 65_536 0xFF 0o755 0b10
|
263 | float-lit 3.14 1.5e-10
|
264 | char-literal \\ \t \" \y00 \u{3bc}
|
265 | X num-suffix 42 K Ki M Mi G Gi T Ti / ms us
|
266 | ysh-string "x is $x" $"x is $x" r'[a-z]\n'
|
267 | u'line\n' b'byte \yff'
|
268 | triple-quoted """ $""" r''' u''' b'''
|
269 | str-template ^"$a and $b" for Str::replace()
|
270 | list-literal ['one', 'two', 3] :| unquoted words |
|
271 | dict-literal {name: 'bob'} {a, b}
|
272 | range 1 ..< n 1 ..= n
|
273 | block-expr ^(echo $PWD)
|
274 | expr-literal ^[1 + 2*3]
|
275 | X expr-sub $[myobj]
|
276 | X expr-splice @[myobj]
|
277 | [Operators] op-precedence Like Python
|
278 | concat s1 ++ s2, L1 ++ L2
|
279 | ysh-equals === !== ~== is, is not
|
280 | ysh-in in, not in
|
281 | ysh-compare < <= > >= (numbers only)
|
282 | ysh-logical not and or
|
283 | ysh-arith + - * / // % **
|
284 | ysh-bitwise ~ & | ^ << >>
|
285 | ysh-ternary '+' if x >= 0 else '-'
|
286 | ysh-index s[0] mylist[3] mydict['key']
|
287 | ysh-attr mydict.key mystr.startsWith('x')
|
288 | ysh-slice a[1:-1] s[1:-1]
|
289 | ysh-func-call f(x, y, ...pos; n=1, ...named)
|
290 | thin-arrow mylist->pop()
|
291 | fat-arrow mylist => join() => upper()
|
292 | match-ops ~ !~ ~~ !~~
|
293 | [Eggex] re-literal / d+ ; re-flags ; ERE /
|
294 | re-primitive %zero 'sq'
|
295 | class-literal [c a-z 'abc' @str_var \\ \xFF \u{3bc}]
|
296 | named-class dot digit space word d s w
|
297 | re-repeat d? d* d+ d{3} d{2,4}
|
298 | re-compound seq1 seq2 alt1|alt2 (expr1 expr2)
|
299 | re-capture <capture d+ as name: int>
|
300 | re-splice Subpattern @subpattern
|
301 | re-flags reg_icase reg_newline
|
302 | X re-multiline ///
|
303 | ```
|
304 |
|
305 | <h2 id="word-lang">
|
306 | Word Language <a class="group-link" href="chap-word-lang.html">word-lang</a>
|
307 | </h2>
|
308 |
|
309 | <!-- linkify_stop_col is 33 -->
|
310 |
|
311 | ```chapter-links-word-lang_33
|
312 | [Quotes] ysh-string "x is $x" $"x is $x" r'[a-z]\n'
|
313 | u'line\n' b'byte \yff'
|
314 | triple-quoted """ $""" r''' u''' b'''
|
315 | X tagged-str "<span id=$x>"html
|
316 | [Substitutions] expr-sub echo $[42 + a[i]]
|
317 | expr-splice echo @[split(x)]
|
318 | var-splice @myarray @ARGV
|
319 | command-sub @(cat my-j8-lines.txt)
|
320 | [Formatting] X ysh-printf ${x %.3f}
|
321 | X ysh-format ${x|html}
|
322 | ```
|
323 |
|
324 | <h2 id="mini-lang">
|
325 | Other Mini Languages <a class="group-link" href="chap-mini-lang.html">mini-lang</a>
|
326 | </h2>
|
327 |
|
328 | <!-- linkify_stop_col is 33 -->
|
329 |
|
330 | ```chapter-links-mini-lang_33
|
331 | [Patterns] glob-pat *.py
|
332 | [Other Sublang] braces {alice,bob}@example.com
|
333 | ```
|
334 |
|
335 | <h2 id="option">
|
336 | Global Shell Options <a class="group-link" href="chap-option.html">option</a>
|
337 | </h2>
|
338 |
|
339 | ```chapter-links-option
|
340 | [Groups] strict:all ysh:upgrade ysh:all
|
341 | [YSH Details] opts-redefine opts-internal
|
342 | ```
|
343 |
|
344 | <h2 id="special-var">
|
345 | Special Variables <a class="group-link" href="chap-special-var.html">special-var</a>
|
346 | </h2>
|
347 |
|
348 | ```chapter-links-special-var
|
349 | [YSH Vars] ARGV ENV __defaults__
|
350 | _this_dir
|
351 | [YSH Status] _error
|
352 | _pipeline_status _process_sub_status
|
353 | [YSH Tracing] SHX_indent SHX_punct SHX_pid_str
|
354 | [YSH read] _reply
|
355 | [History] YSH_HISTFILE
|
356 | [Oils VM] OILS_VERSION
|
357 | OILS_GC_THRESHOLD OILS_GC_ON_EXIT
|
358 | OILS_GC_STATS OILS_GC_STATS_FD
|
359 | LIB_YSH
|
360 | [Float] NAN INFINITY
|
361 | [Module] __provide__
|
362 | [Other Env] HOME PATH
|
363 | ```
|
364 |
|
365 | <!--
|
366 | ENV vars read by interpreter:
|
367 |
|
368 | ENV.{PS1,PS4,YSH_HISTFILE}
|
369 |
|
370 | - renderPrompt() takes precedence over PS1
|
371 | - SHX_* takes precedence over PS4
|
372 | - TODO: we may want to redo this - it is too confusing
|
373 | - HOME is read for ~, but it is not SET
|
374 | - we should read ENV.HOME
|
375 | - should be populate ENV.HOME?
|
376 |
|
377 | Notes:
|
378 | [Module] __E__ - for evalToDict()?
|
379 | X [Builtin Sub] _buffer
|
380 |
|
381 | Ideas:
|
382 | X [Wok] _filename _line _line_num
|
383 | -->
|
384 |
|
385 | <h2 id="plugin">
|
386 | Plugins and Hooks <a class="group-link" href="chap-plugin.html">plugin</a>
|
387 | </h2>
|
388 |
|
389 | ```chapter-links-plugin
|
390 | [YSH] renderPrompt()
|
391 | ```
|