-
-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #190 from yassinebenaid/dev
Rewrite documentation
- Loading branch information
Showing
5 changed files
with
216 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
# Environment Files | ||
We have a first-class support for environment files. Known as [.env files](https://dotenvx.com/docs/env-file). This feature allows you | ||
to load environment variables from environment files and make them available as variables in the shell context. | ||
|
||
This is possible through the `envload` builtin command. | ||
|
||
## Quick Example | ||
You get started, define your variables in a `.env` file. | ||
_.env_: | ||
```sh | ||
KEY=value | ||
``` | ||
|
||
Then use the `loadenv` builtin command: | ||
_script.sh_: | ||
```sh | ||
loadenv | ||
|
||
echo $KEY | ||
|
||
# value | ||
``` | ||
|
||
## Environment file format | ||
We support the standard format of `.env` files. This includes simple keys, quoting, variable references and yaml format. | ||
|
||
```sh | ||
# comments are supported | ||
KEY=value # inline comments are supported too | ||
|
||
# quotes | ||
KEY="foo bar baz" | ||
KEY='foo bar baz' | ||
|
||
# reference other keys | ||
KEY=$KEY | ||
KEY=${KEY} | ||
KEY="$KEY" | ||
KEY="${KEY}" | ||
``` | ||
|
||
### YAML format | ||
We also support the yaml format: | ||
```yaml | ||
# comments are supported | ||
KEY: value # inline comments are supported too | ||
|
||
# quotes | ||
KEY: "foo bar baz" | ||
KEY: 'foo bar baz' | ||
|
||
# reference other keys | ||
KEY: $KEY | ||
KEY: ${KEY} | ||
KEY: "$KEY" | ||
KEY: "${KEY}" | ||
``` | ||
## Command Usage | ||
The command `loadenv` is very streightforward. When you do not pass any arguments. it will default to load `.env` file in current workin directory. | ||
|
||
```sh | ||
loadenv # loads .env in CWD | ||
``` | ||
|
||
You can pass one or many file paths. In this case, the order of the files matters. Because files that come last override keys in files that come first. | ||
|
||
```sh | ||
loadenv file.env file2.yaml file3.env | ||
``` | ||
|
||
### Exporting variables | ||
By default, the variables are only available in the current shell context. They are not exported to child processes. For example: | ||
|
||
_.env_: | ||
```sh | ||
NAME=bunster | ||
``` | ||
|
||
In your script: | ||
|
||
```sh | ||
loadenv | ||
bash -c 'echo env:$NAME' | ||
echo var:$NAME | ||
``` | ||
|
||
This will output: | ||
```txt | ||
env: | ||
var:bunster | ||
``` | ||
|
||
To export them, you can use the `-X` flag to export them: | ||
```sh | ||
loadenv -X | ||
bash -c 'echo env:$NAME' | ||
echo var:$NAME | ||
``` | ||
|
||
This will output: | ||
```txt | ||
env:bunster | ||
var:bunster | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,98 @@ | ||
# Simple Commands | ||
You may run simple commands just like in a regular shell. There is no difference between bash and bunster when it comes to running external commands. | ||
which are external programs accessible through the `$PATH` environment variable. | ||
Just like any other shell scripting language. Bunster allows you can run external progams. | ||
|
||
**Format**: | ||
```shell | ||
The format is as follows: | ||
```sh | ||
command-name [arguments...] | ||
``` | ||
|
||
The command name can be either a program name or a full relative or absolute path to the program. if the name is not a path, the program must be in `$PATH`. | ||
The `command-name` can be a full path to a program. or just the name of the binary. In that case, the binary must be accessible in `$PATH`. | ||
|
||
## Separator | ||
You can separate the command list by a new line. a semicolon `;`, an ampersand `&` or logical operators `&&` and `||`. | ||
|
||
```sh | ||
command argument argument | ||
command2 argument argument; command3 argument argument | ||
command4 argument argument; | ||
``` | ||
|
||
we will talk more about ampersand `&` and logical operators later in the documentation. | ||
|
||
|
||
## Quotes | ||
Quotes in bunster work the exact same as in bash. | ||
### Double Quotes | ||
Quoting in bunster works the exact same as in bash. it preserves the literal value of the characters. for example: | ||
double quotes are used to preserve the literal meaning of tokens except the dollar sign `$`. | ||
|
||
```shell | ||
"command name" "arguments" | ||
```sh | ||
"command name" "foo bar" | ||
``` | ||
|
||
The dollar sign is an exception. | ||
This will run the comand `command name` and pass the argument `foo bar`. | ||
|
||
#### Dollar sign | ||
Dollar sign is a special token that is used for substitution. It does not lose it's meaning in double quotes: | ||
|
||
```shell | ||
```sh | ||
echo "$HOME" | ||
``` | ||
|
||
This will run the command `echo`. the first argument is the value of the variable `HOME`. | ||
This will run `echo`. and passes an argument which is the value of the `HOME` variable. (we will learn more about variables later). | ||
|
||
#### Escaping quotes | ||
You can escape double quotes within double quotes: | ||
|
||
```sh | ||
echo "\"foobar\"" | ||
``` | ||
|
||
This will run the command `echo` with the argument `"foobar"`. | ||
|
||
### Single Quotes | ||
Single quotes are also used to preserve the literal meaning of tokens. However, unlike double quotes, all tokens within single quotes loose their special meaning. | ||
Including the `$` dollar sign. And you cannot use escaping within single quotes | ||
|
||
```sh | ||
echo '$VAR\' | ||
``` | ||
|
||
Runs the command `echo` with the argument `$VAR\` | ||
|
||
|
||
## Escaping | ||
Escaping is the same as in bash. you use the backslash `\` to preserve the literal meaning of the next token. | ||
The backslash it self is removed and the escaped token is treated literally. | ||
|
||
Newline `\n` is a special case. when you scape a newline. the newline is removed as well: | ||
|
||
```sh | ||
command\ name \ | ||
argument argument2 | ||
``` | ||
|
||
This will run the command `command name`. and pass the `argument` and `argument2` arguments. | ||
|
||
## Comments | ||
Comments in bunster are (as you may guess) the exact as in any other shell. Lines starting with `#` are ignored. | ||
Parts of lines that start with `#` are treated as comments as well and are ignored. | ||
|
||
```sh | ||
# full line comment | ||
command # inline comment | ||
``` | ||
|
||
|
||
## Examples | ||
```sh | ||
echo foo bar | ||
|
||
echo "Hello World" | ||
|
||
echo 'Hello World' | ||
|
||
echo; echo | ||
|
||
echo \ | ||
foo bar | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters