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