dotenv-matlab

版本 1.0 (37.7 KB) 作者: Pavel Roslovets
Load environment variables from .env file
22.0 次下载
更新时间 2022/3/15

matlab-dotenv

Load environment variables from .env file

Description

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.

Installation

Approach 1 (easy and fast)

Execute in MATLAB:

eval(webread('https://raw.githubusercontent.com/roslovets/matlab-dotenv/main/installer/installweb.m'))

Approach 2 (manual)

Use Add-Ons Explorer in MATLAB to find and install matlab-dotenv.

Approach 3 (offline)

Download matlab-dotenv.mltbx from the latest release and open it in MATLAB.

Load environment variables

Use dotenv.load function to load environment variables from .env file.

Syntax

dotenv.load

dotenv.load(dotEnvFilePath)

Description

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

Input arguments

  • dotEnvFilePath - absolute or relative path to the text file with env variables (.env). Scalar string | char array

Read environment variables

Use dotenv.read function to read environment variables from .env file to structure.

Syntax

env = dotenv.read

env = dotenv.read(dotEnvFilePath)

Description

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

Input arguments

  • dotEnvFilePath - absolute or relative path to the text file with env variables (.env). Scalar string | char array

Output arguments

  • env - structure with values of variables. Scalar struct

Example

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

引用格式

Pavel Roslovets (2024). dotenv-matlab (https://github.com/roslovets/matlab-dotenv/releases/tag/v1.0), GitHub. 检索来源 .

MATLAB 版本兼容性
创建方式 R2022a
与 R2016b 及更高版本兼容
平台兼容性
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

dev

installer

main/code

main/code/+dotenv

版本 已发布 发行说明
1.0

要查看或报告此来自 GitHub 的附加功能中的问题,请访问其 GitHub 仓库
要查看或报告此来自 GitHub 的附加功能中的问题,请访问其 GitHub 仓库