OILS / doc / ref / toc-ysh.md View on Github | oilshell.org

313 lines, 273 significant
1---
2title: YSH Table of Contents
3all_docs_url: ..
4css_files: ../../web/base.css ../../web/manual.css ../../web/ref-index.css
5preserve_anchor_case: yes
6---
7
8<div class="doc-ref-header">
9
10[Oils Reference](index.html) &mdash;
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
16error handling, and more.
17
18<!--
19<div class="custom-toc">
20
21[type-method](#type-method) &nbsp;
22[builtin-func](#builtin-func) &nbsp;
23[builtin-cmd](#builtin-cmd) &nbsp;
24[front-end](#front-end) &nbsp;
25[cmd-lang](#cmd-lang) &nbsp;
26[ysh-cmd](#ysh-cmd) &nbsp;
27[expr-lang](#expr-lang) &nbsp;
28[word-lang](#word-lang) &nbsp;
29[mini-lang](#mini-lang) &nbsp;
30[option](#option) &nbsp;
31[special-var](#special-var) &nbsp;
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
60X [Func] name() location() toJson()
61X [Proc] name() location() toJson()
62X [Module] name() filename()
63 [IO] X eval() X captureStdout()
64 promptVal()
65 X time() X strftime()
66 X glob()
67X [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() X repeat()
76 [Conversions] bool() int() float() str() list() dict()
77 X chr() X ord() X runes()
78 [Str] X strcmp() X split() shSplit()
79 [List] join() any() all()
80 [Collections] X copy() X deepCopy()
81 [Word] glob() maybe()
82 [Math] abs() max() min() X round() sum()
83 [Serialize] toJson() fromJson()
84 toJson8() fromJson8()
85X [J8 Decode] J8.Bool() J8.Int() ...
86 [Pattern] _group() _start() _end()
87 [Introspection] shvarGet() getVar() evalExpr()
88 [Hay Config] parseHay() evalHay()
89X [Hashing] sha1dc() sha256()
90```
91
92<!-- ideas
93X [Codecs] quoteUrl() quoteHtml() quoteSh() quoteC()
94 quoteMake() quoteNinja()
95X [Wok] _field()
96-->
97
98<h2 id="builtin-cmd">
99 Builtin Commands <a class="group-link" href="chap-builtin-cmd">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 asdl cell X gc-stats line proc
107 [Handle Errors] try Run with errexit, set _status _error
108 boolstatus Enforce 0 or 1 exit status
109 error error 'failed' (status=2)
110 [Shell State] ysh-cd ysh-shopt compatible, and takes a block
111 shvar Temporary modify global settings
112 ctx Share and update a temporary "context"
113 push-registers Save registers like $?, PIPESTATUS
114 [Modules] runproc Run a proc; use as main entry point
115 module guard against duplicate 'source'
116 is-main false when sourcing a file
117 use change first word lookup
118 [I/O] ysh-read flags --all, -0
119 ysh-echo no -e -n with simple_echo
120 write Like echo, with --, --sep, --end
121 fork forkwait Replace & and (), and takes a block
122 fopen Open multiple streams, takes a block
123 X dbg Only thing that can be used in funcs
124 X log X die Common functions (polyfill)
125 [Hay Config] hay haynode For DSLs and config files
126 [Completion] compadjust compexport
127 [Data Formats] json read write
128 json8 read write
129X [TSV8] rows pick rows; dplyr filter()
130 cols pick columns ('select' already taken)
131 group-by add a column with a group ID [ext]
132 sort-by sort by columns; dplyr arrange() [ext]
133 summary count, sum, histogram, etc. [ext]
134 [Args Parser] parser Parse command line arguments
135 flag
136 arg
137 rest
138 parseArgs()
139X [Testing] describe Test harness
140 assert takes an expression
141```
142
143<!--
144Naming ideas:
145
146X [External Lang] BEGIN END when (awk)
147 rule (make) each (xargs) fs (find)
148-->
149
150<h2 id="front-end">
151 Front End <a class="group-link" href="chap-front-end.html">front-end</a>
152</h2>
153
154```chapter-links-front-end
155 [Usage] oils-usage ysh-usage
156 [Lexing] ascii-whitespace [ \t\r\n]
157 doc-comment ### multiline-command ...
158 [Tools] cat-em
159```
160
161<h2 id="cmd-lang">
162 Command Language <a class="group-link" href="chap-cmd-lang.html">cmd-lang</a>
163</h2>
164
165<!-- linkify_stop_col is 33 -->
166
167```chapter-links-cmd-lang_33
168 [YSH Simple] typed-arg json write (x)
169 lazy-expr-arg assert [42 === x]
170 block-arg cd /tmp { echo $PWD }; cd /tmp (; ; blockexpr)
171 [YSH Cond] ysh-case case (x) { *.py { echo 'python' } }
172 ysh-if if (x > 0) { echo }
173 [YSH Iter] ysh-while while (x > 0) { echo }
174 ysh-for for i, item in (mylist) { echo }
175```
176
177<h2 id="ysh-cmd">
178 YSH Command Language Keywords <a class="group-link" href="chap-ysh-cmd.html">ysh-cmd</a>
179</h2>
180
181```chapter-links-ysh-cmd_33
182 [Assignment] const var Declare variables
183 setvar setvar a[i] = 42
184 setglobal setglobal d.key = 'foo'
185 [Expression] equal = = 1 + 2*3
186 call call mylist->append(42)
187 [Definitions] proc proc p (s, ...rest) {
188 typed proc p (; typed, ...rest; n=0; b) {
189 func func f(x; opt1, opt2) { return (x + 1) }
190 ysh-return return (myexpr)
191```
192
193<h2 id="expr-lang">
194 Expression Language and Assignments <a class="group-link" href="chap-expr-lang.html">expr-lang</a>
195</h2>
196
197<!-- linkify_stop_col is 33 -->
198
199```chapter-links-expr-lang_33
200 [Assignment] assign =
201 aug-assign += -= *= /= **= //= %=
202 &= |= ^= <<= >>=
203 [Literals] atom-literal true false null
204 int-literal 42 65_536 0xFF 0o755 0b10
205 float-lit 3.14 1.5e-10
206 X num-suffix 42 K Ki M Mi G Gi T Ti / ms us
207 ysh-string "x is $x" $"x is $x" r'[a-z]\n'
208 u'line\n' b'byte \yff'
209 triple-quoted """ $""" r''' u''' b'''
210 str-template ^"$a and $b" for Str::replace()
211 list-literal ['one', 'two', 3] :| unquoted words |
212 dict-literal {name: 'bob'} {a, b}
213 range 1 .. n+1
214 block-expr ^(echo $PWD)
215 expr-literal ^[1 + 2*3]
216 X expr-sub $[myobj]
217 X expr-splice @[myobj]
218 [Operators] op-precedence Like Python
219 concat s1 ++ s2, L1 ++ L2
220 ysh-equals === !== ~== is, is not
221 ysh-in in, not in
222 ysh-compare < <= > >= (numbers only)
223 ysh-logical not and or
224 ysh-arith + - * / // % **
225 ysh-bitwise ~ & | ^ << >>
226 ysh-ternary '+' if x >= 0 else '-'
227 ysh-index s[0] mylist[3] mydict['key']
228 ysh-attr mydict.key
229 ysh-slice a[1:-1] s[1:-1]
230 func-call f(x, y; ...named)
231 thin-arrow mylist->pop()
232 fat-arrow mystr => startsWith('prefix')
233 match-ops ~ !~ ~~ !~~
234 [Eggex] re-literal / d+ ; re-flags ; ERE /
235 re-primitive %zero 'sq'
236 class-literal [c a-z 'abc' @str_var \\ \xFF \u0100]
237 named-class dot digit space word d s w
238 re-repeat d? d* d+ d{3} d{2,4}
239 re-compound seq1 seq2 alt1|alt2 (expr1 expr2)
240 re-capture <capture d+ as name: int>
241 re-splice Subpattern @subpattern
242 re-flags reg_icase reg_newline
243 X re-multiline ///
244```
245
246<h2 id="word-lang">
247 Word Language <a class="group-link" href="chap-word-lang.html">word-lang</a>
248</h2>
249
250<!-- linkify_stop_col is 33 -->
251
252```chapter-links-word-lang_33
253 [Quotes] ysh-string "x is $x" $"x is $x" r'[a-z]\n'
254 u'line\n' b'byte \yff'
255 triple-quoted """ $""" r''' u''' b'''
256 X tagged-str "<span id=$x>"html
257 [Substitutions] expr-sub echo $[42 + a[i]]
258 expr-splice echo @[split(x)]
259 var-splice @myarray @ARGV
260 command-sub @(split command)
261 [Formatting] X ysh-printf ${x %.3f}
262 X ysh-format ${x|html}
263```
264
265<h2 id="mini-lang">
266 Other Mini Languages <a class="group-link" href="chap-mini-lang.html">mini-lang</a>
267</h2>
268
269<!-- linkify_stop_col is 33 -->
270
271```chapter-links-mini-lang_33
272 [Patterns] glob-pat *.py
273 [Other Sublang] braces {alice,bob}@example.com
274```
275
276<h2 id="option">
277 Global Shell Options <a class="group-link" href="chap-option.html">option</a>
278</h2>
279
280```chapter-links-option
281 [Groups] strict:all ysh:upgrade ysh:all
282 [YSH Details] opts-redefine opts-internal
283```
284
285<h2 id="special-var">
286 Special Variables <a class="group-link" href="chap-special-var.html">special-var</a>
287</h2>
288
289```chapter-links-special-var
290 [YSH Vars] ARGV X ENV X _ESCAPE
291 _this_dir
292 [YSH Status] _status _error
293 _pipeline_status _process_sub_status
294 [YSH Tracing] SHX_indent SHX_punct SHX_pid_str
295 [YSH read] _reply
296 [History] YSH_HISTFILE
297 [Oils VM] OILS_VERSION
298 OILS_GC_THRESHOLD OILS_GC_ON_EXIT
299 OILS_GC_STATS OILS_GC_STATS_FD
300```
301
302<!-- ideas
303X [Wok] _filename _line
304X [Builtin Sub] _buffer
305-->
306
307<h2 id="plugin">
308 Plugins and Hooks <a class="group-link" href="chap-plugin.html">plugin</a>
309</h2>
310
311```chapter-links-plugin
312 [YSH] renderPrompt()
313```