From 84743879d4a4c44616c89be1bb3d94a2a705d500 Mon Sep 17 00:00:00 2001 From: Quentin Nerden Date: Fri, 4 Feb 2022 13:25:15 +0100 Subject: [PATCH] Update README: expand envvars section --- README.adoc | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/README.adoc b/README.adoc index dbeb3b5f59..0766501771 100644 --- a/README.adoc +++ b/README.adoc @@ -936,7 +936,7 @@ The executable is at: /bin/just ==== Dotenv Integration -`just` will load environment variables from a file named `.env`. This file can be located in the same directory as your justfile or in a parent directory. These variables are environment variables, not `just` variables, and so must be accessed using `$VARIABLE_NAME` in recipes and backticks. +`just` will load environment variables from a file named `.env` if the setting [dotenv-load](https://github.com/casey/just#dotenv-load) is present. This file can be located in the same directory as your justfile or in a parent directory. These variables are environment variables, not `just` variables, and so must be accessed using `$VARIABLE_NAME` in recipes and backticks. For example, if your `.env` file contains: @@ -1126,6 +1126,12 @@ $ just --set os bsd === Environment Variables +==== How to pass environment variables to recipes + +There are two ways to pass environment variables to recipes: exporting `just` variables, or using an `.env` file. + +===== Exporting `just` variables + Assignments prefixed with the `export` keyword will be exported to recipes as environment variables: ```make @@ -1158,6 +1164,17 @@ a $A $B=`echo $A`: echo $A $B ``` +Note: the setting link:README.adoc#export[export] causes all `just` variables to be exported to recipes as enviroment variables. + +===== Using an `.env` file + +`just` can load an .env file if the setting link:README.adoc#dotenv-load[dotenv-load] is present. The variables in the file will be available as environment variables to the recipes. See link:README.adoc#dotenv-integration[here] for more information. + +==== Loading `just` variables from the shell environments variables + +Environment variables from the shell can be loaded as variables in `just` with the functions `env_var()` and `en_var_or_default()`, described link:README.adoc#environment-variables[here]. +They could then be exported to the recipes using link:README.adoc#exporting-just-variables[export]. + === Recipe Parameters Recipes may have parameters. Here recipe `build` has a parameter called `target`: