on 2ddfcbb help sign in
413 lines 8.2 kB history raw
1+++
2title = "Shell"
3template = "doc.html"
4weight = 2
5+++
7The Dojo is our shell; it processes system commands and returns output. It's a
8good place to quickly experiment with Urbit. On the surface the Dojo is just a
9Hoon REPL. On the inside, the Dojo is a system for operating on and transforming
10data in Urbit.
12### Quickstart
14You can use the Dojo to run arbitrary Hoon code, as well as non-Hoon system
15commands.
17#### Math
19Evaluate a Hoon expression (whitespace matters):
21```
22~your-urbit:dojo> (add 2 2)
23~your-urbit:dojo> %+ add 2 2
24```
26Tall-form Hoon may require multiple lines:
28```
29~your-urbit:dojo> %+ add
30~your-urbit:dojo< 2
31~your-urbit:dojo< 2
32```
34Hoon uses something called [the subject](/docs/hoon/hoon-school/the-subject-and-its-legs).
35The Dojo has its own subject and that's where Hoon's equivalent of variables,
36called faces, are stored.
38Use `=var` to save faces to the Dojo subject.
40```
41~your-urbit:dojo> =foo (add 2 2)
42```
44Note, however, that `=var` is Dojo syntax, not Hoon syntax. You cannot bind a
45face in a `.hoon` file in this way.
47#### System commands
49Use `=dir` to set the current working directory:
51```
52~your-urbit:dojo> =dir %/gen
53```
55(`%` represents your current directory. For a complete explanation on urbit
56paths, see the [filesystem section](#filesystem).)
58Generators (files in `/gen`) are run with `+`:
60```
61~your-urbit:dojo> +hello 'world'
62```
64Save output to a file in `%clay` with `*`:
66```
67~your-urbit:dojo> *some/file/path/hoon 'hello world'
68```
70Run system commands from `:hood`, like `reload`, using `|`:
72```
73~your-urbit:dojo> |reload %eyre
74```
76### Generators
78Generators are short Hoon scripts, saved as `.hoon` files in the `/gen`
79directory. Many Dojo commands exist in the form of generators. The syntax for
80running a generator is `+genname` for a generator saved as `genname.hoon`.
82#### `+cat`
84Accepts a path and displays the file. Similar to Unix `cat`.
86```
87~your-urbit:dojo> +cat %/gen/curl/hoon
88```
90#### `+code`
92Generates a code that is used to remotely log into your ship. No
93arguments.
95```
96~your-urbit:dojo> +code
97```
99You can change your code to a new randomly generated one by entering `|code
100%reset`. Please note that this will prevent [Bridge](/docs/glossary/bridge)
101from being able to derive your code in the future.
103#### `+curl`
105Retrieves data from a URL. Accepts a `tape`. Similar to Unix `curl`.
107```
108~your-urbit:dojo> +curl "http://nyt.com"
109```
111#### `+hello`
113Just prints the argument. Accepts a `@ta`.
115```
116~your-urbit:dojo> +hello 'mars'
117```
119#### `+ls`
121Similar to Unix `ls`. Accepts a path.
123```
124~your-urbit:dojo> +ls %/gen
125~your-urbit:dojo> +ls /~talsur-todres/home/2/gen/program
126```
128#### `+solid`
130Compile the current state of the kernel and output a
131noun. Usually downloaded to a file in unix. No arguments.
133```
134~your-urbit:dojo> .urbit/pill +solid
135```
137#### `+test`
139Testrunner. Can test multiple generators at once, conventionally ones
140in the `/test` folder. Takes a path.
142```
143~your-urbit:dojo> +test /lib
144```
146#### `+ticket`
148Generate a ticket for an urbit ship. Takes an urbit name (`@p`).
151```
152~your-urbit:dojo> +ticket ~talsur-todres-your-urbit
153```
155#### `+tree`
157Generate a recursive directory listing. Takes a path.
159```
160~your-urbit:dojo> +tree %/sys
161```
163### Hood
165The hood is the system daemon. See `gen/hood` and `app/hood`.
167`|hi` - Sends a direct message. Sort of like Unix `write`. Accepts
168an urbit name (`@p`) and a string (`tape`, which is text wrapped with double-quotes).
170```
171~your-urbit:dojo> |hi ~binzod "you there?"
172```
174`|link` / `|unlink` - Link / unlink a remote app. Accepts an
175Urbit name and an app name.
177```
178~your-urbit:dojo> |link ~talsur-todres %octo
179```
181`|mass` - Prints the current memory usage of all the kernel modules.
182No arguments.
184```
185~your-urbit:dojo> |mass
186```
188`|reload` - Reloads a kernel module (vane) from source. Accepts any
189number of vane names.
191```
192~your-urbit:dojo> |reload %clay %eyre
193```
195`|reset` - Reloads `hoon.hoon` and all modules. No arguments.
197```
198~your-urbit:dojo> |reset
199```
201`|start` - Starts an app. Accepts an app name.
203```
204~your-urbit:dojo> |start %curl
205```
207---
209### Dojo manual
211#### Sources and sinks
213A Dojo command is either a **source** or a **sink**. A source is just something
214that can be printed to your console or the result of some computation. A
215sink is an **effect**: a change to the filesystem, a network message, a
216change to your environment, or a typed message to an app.
218Sources can be chained together, but we can only produce one effect per
219command.
221#### Sinks
223#### `=` - Set variable
225Set any environment variable:
227```
228~your-urbit:dojo> =foo 42
229~your-urbit:dojo> (add 2 foo)
23144
232```
234Make sure to note that `=var` is Dojo syntax, not Hoon syntax. You cannot bind a
235variable in a `.hoon` file in this way.
237#### Special variables
239There are a few special variables that the Dojo maintains.
241#### `:` - Send to app
243`:app` goes to a local `app`, `:~ship/app` goes to the `app` on `~ship`.
245Send a `helm-hi` message to `hood`:
247```
248~your-urbit:dojo> :hood &helm-hi 'hi'
249```
251Apps usually expect marked data, so `&` is often used here.
253#### `*` - Save in `%clay`
255Save a new `.hoon` file in `gen`:
257```
258~your-urbit:dojo> *%/gen/foo/hoon '# hello'
259```
261The last component of the path is expected to be the mark (or mime
262type).
264#### `.` - Export to Unix
266Export a noun to Unix with `.`:
268```
269~your-urbit:dojo> .foo/bar/baz (add 2 2)
270```
272Which creates a file at `pier/.urb/put/foo/bar.baz`.
274This is very often used with `+solid`:
276```
277~your-urbit:dojo> .urbit/pill +solid
278```
280Which outputs a new `urbit.pill` to `pier/.urb/put/urbit.pill`
282### Sources
284#### `_` - Run a function
286Use `_` to run a gate (or function):
288Write an arbitrary function and pass data to it:
290```
291~your-urbit:dojo> _|=([a=@] (mul a 3)) 3
293```
295Use a function to get the status code from an http request:
297```
298~your-urbit:dojo> _|=([p=@ud q=* r=*] p) +http://google.com
299301
300```
302#### `+` `-` - HTTP requests
304`+http[s]://example.com` - sends a GET request
306`+http[s]://example.com &json [%s 'hi']` - sends a POST request with the
307JSON `"hi"` in the body.
309`-http[s]://example.com &json [%s 'hi']` - sends a PUT request with the
310JSON `"hi"` in the body.
312Note that the first of these is a source while the last two are sinks.
314#### `+` - Generators
316Generators are simple Hoon scripts loaded from the filesystem. They live
317in `gen/`.
319An example of a generator that is built into your urbit is `+code`. It produces
320the code needed to log into your ship remotely.
322```
323~your-urbit:dojo> +code
324fintyr-haldet-fassev-solhex
325```
327### Variables
329You can use `=` to set an environment variable in Dojo, but there are
330a few reserved names that have special uses.
332#### `dir`
334Current working `%clay` desk and revision. Read / write.
336**Examples:**
338```
339~your-urbit:dojo> =dir %/gen
340~your-urbit:dojo> +ls %
341404/hoon docs/ dojo/hoon lib/ listen/hoon md static/udon talk/ testing/udon tree/main/ unmark/ womb/
342```
344#### `lib`
346Current set of libraries (`/lib`) in your environment. Can be set
347with `/+`. Read / write.
349**Examples:**
351```
352~your-urbit:dojo> /+ number-to-words
353```
354Now we can use arms from lib/number-to-words.hoon
355```
356~your-urbit:dojo> (to-words:eng-us:number-to-words 123.456)
357```
359#### `sur`
361Current set of structures (`/sur`) in your environment. Can be set
362with `/-`. Read / write.
364**Examples:**
366```
367~your-urbit:dojo> /- sole
368```
369Now we can use arms in sur/sole.hoon.
370```
371~your-urbit:dojo> `sole-effect:sole`[%bel ~]
372```
374#### `now`
376The current (128-bit `@da`) time. Read-only.
378**Example:**
380```
381~your-urbit:dojo> now
382~2016.3.21..21.10.57..429a
383```
385#### `our`
387The current urbit ship. Read-only.
389**Example:**
391```
392~your-urbit:dojo> our
393~your-urbit
394```
396#### `eny`
398512 bits of entropy. Read-only.
400**Example:**
402```
403~your-urbit:dojo> eny
404\/0vnt.d474o.gpahj.jcf3o.448fh.2lamb.82ljm.8ol8u.b02vi.mrvvp.b7et2.knb7m.l8he\/
405 8.8qb9s.drm36.77n9b.a0qst.30g03.l5lb5.nvsbc.v39tn
406\/
407```
409### Troubleshooting
411If you encounter `%dy-edit-busy` while entering commands, it is
412because your Dojo is blocked on a timer or an HTTP request. Type backspace
413and your Dojo will end the blocked command.