Load environment variables from .env file
Use .env files to store sensitive parameters like passwords, tokens, API keys etc. This tool allows you to automatically load all environment variables from .env
file stored in current folder.
Execute in MATLAB:
eval(webread('https://raw.githubusercontent.com/roslovets/matlab-dotenv/main/installer/installweb.m'))
Use Add-Ons Explorer in MATLAB to find and install matlab-dotenv.
Download matlab-dotenv.mltbx from the latest release and open it in MATLAB.
Use dotenv.load
function to load environment variables from .env
file.
dotenv.load
dotenv.load(dotEnvFilePath)
dotenv.load
loads all environment variables from .env
stored in current folder. Access loaded variables with getenv(___)
dotenv.load(dotEnvFilePath)
allows you to specify absolute or relative path to the text file with env variables
dotEnvFilePath
- absolute or relative path to the text file with env variables (.env
). Scalar string | char array
Use dotenv.read
function to read environment variables from .env
file to structure.
env = dotenv.read
env = dotenv.read(dotEnvFilePath)
env = dotenv.read
reads all environment variables from .env
stored in current folder into structure
env = dotenv.read(dotEnvFilePath)
allows you to specify absolute or relative path to the text file with env variables
dotEnvFilePath
- absolute or relative path to the text file with env variables (.env
). Scalar string | char array
env
- structure with values of variables. Scalar struct
In current folder create file named .env
file with content:
var1=text_value
mypass=securely_stored_password
Run this command in your script to load variables from created file:
dotenv.load
Access variables with built-in MATLAB function:
mypass = getenv("mypass")
If you use Git in your project add .env
file to .gitignore
.
Generated from GettingStarted.mlx with Live Script to Markdown Converter