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