2022-02-14 03:22:51 +01:00
|
|
|
---
|
|
|
|
title: def
|
|
|
|
layout: command
|
2022-03-04 13:10:09 +01:00
|
|
|
version: 0.59.1
|
2022-02-14 03:22:51 +01:00
|
|
|
---
|
2021-01-15 08:21:18 +01:00
|
|
|
|
2022-02-14 03:22:51 +01:00
|
|
|
Define a custom command
|
2021-01-15 08:21:18 +01:00
|
|
|
|
2022-02-14 03:22:51 +01:00
|
|
|
## Signature
|
2021-01-15 08:21:18 +01:00
|
|
|
|
2022-02-14 03:22:51 +01:00
|
|
|
```> def (def_name) (params) (block)```
|
2021-01-15 08:21:18 +01:00
|
|
|
|
2022-02-14 03:22:51 +01:00
|
|
|
## Parameters
|
2021-01-27 18:31:29 +01:00
|
|
|
|
2022-02-14 03:22:51 +01:00
|
|
|
- `def_name`: definition name
|
|
|
|
- `params`: parameters
|
|
|
|
- `block`: body of the definition
|
2021-01-27 18:31:29 +01:00
|
|
|
|
2022-02-20 02:13:33 +01:00
|
|
|
## Examples
|
|
|
|
|
|
|
|
Define a command and run it
|
|
|
|
```shell
|
|
|
|
> def say-hi [] { echo 'hi' }; say-hi
|
|
|
|
```
|
|
|
|
|
|
|
|
Define a command and run it with parameter(s)
|
|
|
|
```shell
|
|
|
|
> def say-sth [sth: string] { echo $sth }; say-sth hi
|
|
|
|
```
|