Introduction
Firebase functions allow you to set environment variables. For an easy-to-understand guide on setting them, please refer to this article: How to Set Environment Variables in Firebase.
I wanted to use these environment variables in Bash as well, so I devised a command to copy them.
Example of Environment Variables
Assume the following environment variables are registered in Firebase functions:
{
"hoge": {
"client_id": "fuga"
"client_secret": "piyo",
}
}
The goal here is to copy the client_id and client_secret into Bash.
Installing jq
To parse JSON, we need the command-line tool jq.
# Mac
brew install jq
# Windows
choco install jq
# Ubuntu
apt-get install jq
# CentOS
yum install jq
Registering in Bash Environment Variables
You can register them with the following command:
export $(firebase functions:config:get | jq -r '.hoge' | jq -r 'keys[] as $k | "export \($k)=\(.[$k])"')
Replace hoge with the appropriate value as needed.
This method was inspired by the article Export JSON key:value to environment variables.
Verifying Bash Environment Variables
$ echo ${client_id}
fuga
$ echo ${client_secret}
piyo
The variables were successfully copied.
Conclusion
The following articles were invaluable references. Thank you for the clear guidance.
Top comments (0)