OILS / doc / ref / chap-special-var.md View on Github | oilshell.org

267 lines, 146 significant
1---
2in_progress: yes
3body_css_class: width40 help-body
4default_highlighter: oils-sh
5preserve_anchor_case: yes
6---
7
8Special Variables
9===
10
11This chapter in the [Oils Reference](index.html) describes special variables
12for OSH and YSH.
13
14<div id="toc">
15</div>
16
17## YSH Vars
18
19### ARGV
20
21Replacement for `"$@"`
22
23### ENV
24
25TODO
26
27### _this_dir
28
29The directory the current script resides in. This knows about 3 situations:
30
31- The location of `oshrc` in an interactive shell
32- The location of the main script, e.g. in `osh myscript.sh`
33- The location of script loaded with the `source` builtin
34
35It's useful for "relative imports".
36
37## YSH Status
38
39### `_status`
40
41An `Int` that's set by the `try` builtin.
42
43 try {
44 ls /bad # exits with status 2
45 }
46 if (_status !== 0) { # _status is 2
47 echo 'failed'
48 }
49
50### `_error`
51
52A `Dict` that's set by the `try` builtin when catching certain errors.
53
54Such errors include JSON/J8 encoding/decoding errors, and user errors from the
55`error` builtin.
56
57 try {
58 echo $[toJson( /d+/ )] # invalid Eggex type
59 }
60 echo "failed: $[_error.message]" # => failed: Can't serialize ...
61
62### `_pipeline_status`
63
64Alias for [PIPESTATUS]($osh-help).
65
66### `_process_sub_status`
67
68The exit status of all the process subs in the last command.
69
70## YSH Tracing
71
72### SHX_indent
73
74### SHX_punct
75
76### SHX_pid_str
77
78## YSH Read
79
80### _reply
81
82YSH `read` sets this variable:
83
84 read --all < myfile
85 echo $_reply
86
87## Oils VM
88
89### `OILS_VERSION`
90
91The version of Oils that's being run, e.g. `0.9.0`.
92
93<!-- TODO: specify comparison algorithm. -->
94
95### `OILS_GC_THRESHOLD`
96
97At a GC point, if there are more than this number of live objects, collect
98garbage.
99
100### `OILS_GC_ON_EXIT`
101
102Set `OILS_GC_ON_EXIT=1` to explicitly collect and `free()` before the process
103exits. By default, we let the OS clean up.
104
105Useful for ASAN testing.
106
107### `OILS_GC_STATS`
108
109When the shell process exists, print GC stats to stderr.
110
111### `OILS_GC_STATS_FD`
112
113When the shell process exists, print GC stats to this file descriptor.
114
115## Shell Vars
116
117### IFS
118
119Used for word splitting. And the builtin `shSplit()` function.
120
121### LANG
122
123TODO: bash compat
124
125### GLOBIGNORE
126
127TODO: bash compat
128
129## Shell Options
130
131### SHELLOPTS
132
133bash compat: serialized options for the `set` builtin.
134
135### BASHOPTS
136
137bash compat: serialized options for the `shopt` builtin.
138
139## Other Env
140
141### HOME
142
143$HOME is used for:
144
1451. ~ expansion
1462. ~ abbreviation in the UI (the dirs builtin, \W in $PS1).
147
148Note: The shell doesn't set $HOME. According to POSIX, the program that
149invokes the login shell sets it based on /etc/passwd.
150
151### PATH
152
153A colon-separated string that's used to find executables to run.
154
155
156## POSIX Special
157
158## Other Special
159
160### BASH_REMATCH
161
162Result of regex evaluation `[[ $x =~ $pat ]]`.
163
164### PIPESTATUS
165
166Exit code of each element in a pipeline.
167
168
169## Call Stack
170
171## Tracing
172
173### LINENO
174
175## Process State
176
177### BASHPID
178
179TODO
180
181### PPID
182
183TODO
184
185### UID
186
187### EUID
188
189## Process Stack
190
191## Shell State
192
193## Completion
194
195### COMP_WORDS
196
197An array of words, split by : and = for compatibility with bash. New
198completion scripts should use COMP_ARGV instead.
199
200### COMP_CWORD
201
202Discouraged; for compatibility with bash.
203
204### COMP_LINE
205
206Discouraged; for compatibility with bash.
207
208### COMP_POINT
209
210Discouraged; for compatibility with bash.
211
212### COMPREPLY
213
214User-defined completion functions should Fill this array with candidates. It
215is cleared on every completion request.
216
217### COMP_ARGV
218
219An array of partial command arguments to complete. Preferred over COMP_WORDS.
220The compadjust builtin uses this variable.
221
222(An OSH extension to bash.)
223
224## History
225
226### HISTFILE
227
228Override the default OSH history location.
229
230### YSH_HISTFILE
231
232Override the default YSH history location.
233
234## cd
235
236### PWD
237
238### OLDPWD
239
240### CDPATH
241
242## getopts
243
244### OPTIND
245
246### OPTARG
247
248### OPTERR
249
250## read
251
252### REPLY
253
254OSH read sets this:
255
256 read < myfile
257
258## Functions
259
260### RANDOM
261
262bash compat
263
264### SECONDS
265
266bash compat
267