https://github.com/ronanyeah/bash-export
how to use bash to export your vars
https://github.com/ronanyeah/bash-export
Last synced: about 1 month ago
JSON representation
how to use bash to export your vars
- Host: GitHub
- URL: https://github.com/ronanyeah/bash-export
- Owner: ronanyeah
- License: mit
- Created: 2015-09-23T09:58:21.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2015-12-05T13:34:05.000Z (over 10 years ago)
- Last Synced: 2025-03-30T11:34:11.425Z (about 1 year ago)
- Homepage:
- Size: 4.88 KB
- Stars: 4
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Exporting environment variables using a bash script.
How to move away from [foreman](https://www.npmjs.com/package/foreman) etc for your environment variables and be a sick dev.
**Step 1**
Create a file in your project root folder called *env.sh* (or *anything.sh*).
**Step 2**
Put *env.sh* in your *.gitignore*.
**Step 3**
PUT *ENV.SH* IN YOUR *.GITIGNORE*.
**Step 4**
Format your file like this:
```
#!/bin/bash
export TEST_VAR='env vars loaded'
export ENVIRONMENT_VARIABLE_NAME=whatever
export ENV2=etc
export YOU_GET_THE_PICTURE=lol
printenv TEST_VAR
```
The `printenv TEST_VAR` isn't necessary but I like to add it to give me some feedback that they have loaded correctly.
**Step 5**
From the terminal, run: `$ . env.sh`.
**Step 6**
If it doesn't work, or the printenv doesn't show, run `$ chmod 755 env.sh` and try again.
(Got that trick from [here](http://ryanstutorials.net/bash-scripting-tutorial/bash-script.php).)
**Bonus**
On Windows you can use a PowerShell file called `env.ps1` formatted like this to export your variables:
```
Set-Item -path env:TEST_VAR -value 'env vars loaded'
Set-Item -path env:ENVIRONMENT_VARIABLE_NAME -value 'whatever'
Set-Item -path env:PORT -value 8888
Get-ChildItem Env:TEST_VAR
```
You can run the script in a PowerShell terminal with `& .\env.ps1`.