OILS / doc / ref / chap-mini-lang.md View on Github | oilshell.org

139 lines, 86 significant
1---
2title: Mini Languages (Oils Reference)
3all_docs_url: ..
4body_css_class: width40
5default_highlighter: oils-sh
6preserve_anchor_case: yes
7---
8
9<div class="doc-ref-header">
10
11[Oils Reference](index.html) &mdash;
12Chapter **Mini Languages**
13
14</div>
15
16This chapter describes "mini-languages" like glob patterns and brace expansion.
17
18In contrast, the main sub languages of YSH are [command](chap-cmd-lang.html),
19[word](chap-word-lang.html), and [expression](chap-expr-lang.html).
20
21<span class="in-progress">(in progress)</span>
22
23<div id="dense-toc">
24</div>
25
26<h2 id="sublang">Other Shell Sublanguages</h2>
27
28## Arithmetic
29
30### arith-context
31
32Arithmetic expressions are parsed and evaluated in many parts of POSIX shell
33and bash.
34
35Static:
36
37 a=$(( x + 1 )) # POSIX shell
38
39 # bash
40 (( a = x + 1 ))
41
42 for (( i = 0; i < n; ++i )); do
43 echo $i
44 done
45
46Dynamic:
47
48 [[ 5 -eq 3+x ]] # but not test 5 -eq 3+x
49
50Array index contexts:
51
52 echo ${a[i+1]} # get
53 echo ${#a[i+1]} # calculate
54
55 a[i+1]=foo # set
56
57 test -v 'a[i+1]' # is item set?
58 [[ -v 'a[i+1]' ]] # is item set?
59
60 printf -v 'a[i+1]' # assign to this location
61 unset 'a[i+1]' # unset location
62
63 echo ${a[@] : i+1 : i+2 } # bash slicing
64
65### sh-numbers
66
67### sh-arith
68
69### sh-logical
70
71### sh-bitwise
72
73## Boolean
74
75### bool-expr
76
77### bool-infix
78
79### bool-path
80
81### bool-str
82
83### bool-other
84
85## Patterns
86
87### glob-pat
88
89TODO: glob syntax
90
91### extglob
92
93TODO: extended glob syntax
94
95### regex
96
97Part of [dbracket](chap-cmd-lang.html#dbracket)
98
99## Other Sublang
100
101### braces
102
103### histsub
104
105History substitution uses `!`.
106
107### char-escapes
108
109These backslash escape sequences are used in [echo
110-e](chap-builtin-cmd.html#echo), [printf](chap-builtin-cmd.html#printf), and in
111C-style strings like `$'foo\n'`:
112
113 \\ backslash
114 \a alert (BEL)
115 \b backspace
116 \c stop processing remaining input
117 \e the escape character \x1b
118 \f form feed
119 \n newline
120 \r carriage return
121 \t tab
122 \v vertical tab
123 \xHH the byte with value HH, in hexadecimal
124 \uHHHH the unicode char with value HHHH, in hexadecimal
125 \UHHHHHHHH the unicode char with value HHHHHHHH, in hexadecimal
126
127Also:
128
129 \" Double quote.
130
131Inconsistent octal escapes:
132
133 \0NNN echo -e '\0123'
134 \NNN printf '\123'
135 echo $'\123'
136
137TODO: Verify other differences between `echo -e`, `printf`, and `$''`. See
138`frontend/lexer_def.py`.
139