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