on d452c09 help sign in
urbit.org/docs/using/shell.md
269 lines 6.8 kB history raw
1---
2next: true
3sort: 5
4title: Shell (:dojo)
5---
7# Shell (`:dojo`)
9<div class="row">
10<div class="col-md-8">
12The `:dojo` is the place to quickly experiment with Urbit. At first glance the `:dojo` is just a Hoon REPL. Looking a bit deeper the `:dojo` is set up to make operating on and transforming data in Urbit easy.
14</div>
15</div>
17## Quickstart
19Evaluate a hoon expression:
21 ~your-urbit:dojo> (add 2 2)
22 ~your-urbit:dojo> %+ add 2 2
24Tall form Hoon will be prompted for:
26 ~your-urbit:dojo> %+ add
27 ~your-urbit:dojo< 2
28 ~your-urbit:dojo< 2
30Use `=var` to save a shell variable:
32 ~your-urbit:dojo> =foo (add 2 2)
34Use `=dir` to set the current working directory:
36 ~your-urbit:dojo> =dir %/web
38Generators (files in `/gen`) are run with `+`:
40 ~your-urbit:dojo> +hello 'world'
42Save output to a file in `%clay` with `*`:
44 ~your-urbit:dojo> *some/file/path/hoon 'hello world'
46Run system commands from `:hood`, like `reload`, using `|`:
48 ~your-urbit:dojo> |reload %eyre
50## Manual
52<h3 class="first child">Sources and sinks</h3>
54A dojo command is either a source or a sink. A source is just something that can be printed to your console or the result of some computation. A sink is an *effect*: a change to the filesystem, a network message, a change to your environment, or typed message to an app.
56Sources can be chained together, but we can only produce one effect per command.
58### Sinks
60#### `=` - Set variable
62Set any envronment variable:
64 ~your-urbit:dojo> =foo 42
65 ~your-urbit:dojo> (add 2 foo)
67 44
69(There are a few special variables that the dojo expects. See below.)
71#### `:` - Send to app
73`:app` goes to a local `app`, `:~ship/app` goes to the `app` on `~ship`.
75Send a `helm-hi` message to `hood`:
77 ~your-urbit:dojo> :hood &helm-hi 'hi'
79App usually expect marked data, so `&` is often used here.
81#### `*` - Save in `%clay`
83Save a new `md` file in `web`:
85 ~your-urbit:dojo> *%/web/foo/md '# hello'
87The last component of the path is expected to be the mark (or mime type).
89#### `.` - Download to Unix
91Download a noun to Unix with `.`:
93 ~your-urbit:dojo> .foo/bar/baz (add 2 2)
95Which creates a file at `pier/.urb/put/foo/bar.baz`.
97This is very often used with `+solid`:
99 ~your-urbit:dojo> .urbit/pill +solid
101Which outputs a new `urbit.pill` to `pier/.urb/put/urbit.pill`
103### Sources
105#### `&` - Mark conversion
107Convert between marks using `&`:
109 ~your-urbit:dojo> &html &md '# hello'
110 :: produces
111 '<html><head></head><body><div><h1 id="-hello">hello</h1></div></body></html>'
113#### `_` - Run a function
115Use `_` to run a gate (or function):
117 :: assign an arbitrary function and pass data to it
118 ~your-urbit:dojo> _|=({a/@} (mul a 3)) 3
119 :: produces
120 9
121 :: assign an arbitrary function to get the status code from an http request
122 ~your-urbit:dojo> _|=({p/@ud q/* r/*} p) +http://google.com
123 :: produces
124 301
126#### `+` `-` - HTTP requests
128`+http[s]://example.com` - sends a GET request
130`+http[s]://example.com &json [%s 'hi']` - sends a POST request with the JSON `"hi"` in the body.
132`-http[s]://example.com &json [%s 'hi']` - sends a PUT request with the JSON `"hi"` in the body.
134#### `+` - Generators
136Generators are simple hoon scripts loaded from the filesystem. They live in `gen/`.
138Create a random moon (from any planet):
140 ~your-urbit:dojo> +moon
141 :: produces
142 "moon: ~docsun-tamtem-your-urbit; ticket: ~bartug-hodbyr-fognum-ralmud"
144### Variables
146You can use `=` to set an environment variable in `:dojo`, but there are a few reserved names that have special uses.
148#### `dir`
150Current working `%clay` desk and revision. Read / write.
152**Examples:**
154 ~your-urbit:dojo> =dir %/web
155 ~your-urbit:dojo> +ls %
157 404/hoon docs/ dojo/hoon lib/ listen/hoon md static/md talk/ tree/main/
159#### `lib`
161Current set of libraries (`/lib`) in your environment. Can also be set with `/+`. Read / write.
163**Examples:**
165 ~your-urbit:dojo> =lib ~[[%react ~]]
166 ~your-urbit:dojo> :: this also works:
167 ~your-urbit:dojo> /+ react
168 ~your-urbit:dojo> :: now we can use arms from lib/react.hoon
169 ~your-urbit:dojo> (react-vale:react %div)
171#### `sur`
173Current set of structures (`/sur`) in your environment. Can also be set with `/-`. Read / write.
175**Examples:**
177 ~your-urbit:dojo> =sur ~[[%sole ~]]
178 ~your-urbit:dojo> :: this also works:
179 ~your-urbit:dojo> /- sole
180 ~your-urbit:dojo> :: now we can use arms in sur/sole.hoon
181 ~your-urbit:dojo> `sole-effect:sole`[%bel ~]
183#### `now`
185The current (128-bit `@da`) time. Read-only.
187**Example:**
189 ~your-urbit:dojo> now
190 :: produces
191 ~2016.3.21..21.10.57..429a
193#### `our`
195The current urbit plot. Read-only.
197**Example:**
199 ~your-urbit:dojo> our
200 :: produces
201 ~your-urbit
203#### `eny`
205256 bits of entropy. Read-only.
207**Example:**
209 ~your-urbit:dojo> eny
210 :: produces
211 0v1o.m2vio.j5ieb.7tq84.5kcnp.gjn04.9gl2e.tkj5v.0oqk3.iugk8.rhu6o
213### Generators
215**`+cat`** - Similar to Unix `cat`. Accepts a path.
217 ~your-urbit:dojo> +cat %/web/md
218 ~your-urbit:dojo> +cat /~talsur-todres/home/2/web/notes/md
220**`+curl`** - Similar to Unix `curl`. Accepts a `tape`.
222 ~your-urbit:dojo> +curl "http://nyt.com"
224**`+hello`** - Just prints the argument. Accepts a `@ta`.
226 ~your-urbit:dojo> +hello 'mars'
228**`+ls`** - Similar to Unix `ls`. Accepts a path.
230 ~your-urbit:dojo> +ls %/web
231 ~your-urbit:dojo> +ls /~talsur-todres/home/2/web/notes
233**`+moon`** - Generate a random moon from a planet. No arguments.
235**`+solid`** - Compile the current state of the kernel and output a noun. Usually downloaded to a file in unix. No arguments.
237 ~your-urbit:dojo> .urbit/pill +solid
239**`+ticket`** - Generate a ticket for an Urbit plot. Takes an Urbit name (`@p`).
241 ~your-urbit:dojo> +ticket ~talsur-todres-your-urbit
243**`+tree`** - Generate a recursive directory listing. Takes a path.
245 ~your-urbit:dojo> +tree %/web
247### Hood
249The hood is the system daemon. See `gen/hood` and `app/hood`.
251**`|hi`** - Sends a direct message. Sort of like Unix `write`. Accepts an urbit name (`@p`) and a string (`cord`).
253 ~your-urbit:dojo> |hi ~doznec 'you there?'
255**`|link`** / **`|unlink`** - Link / unlink a remote app. Accepts an Urbit name and an app name.
257 ~your-urbit:dojo> |link ~talsur-todres %octo
259**`|mass`** - Prints the current memory usage of all the kernel modules. No arguments.
261**`|reload`** - Reloads a kernel module (vane) from source. Accepts any number of vane names.
263 ~your-urbit:dojo> |reload %clay %eyre
265**`|reset`** - Reloads `hoon.hoon`. No arguments.
267**`|start`** - Starts an app. Accepts an app name.
269 ~your-urbit:dojo> |start %curl