Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

env -0 dump environment. But how to load it?

The linux command line tool env can dump the current environment.

Since there are some special characters I want to use env -0 (end each output line with 0 byte rather than newline).

But how to load this dump again?

Bash Version: 4.2.53

like image 425
guettli Avatar asked Aug 24 '16 09:08

guettli


People also ask

How do I import a .env variable?

On the Projects page, select the project that you want to import environment variables to, and click Properties to open the Project Properties window. On the General page, click Environment. In the Environment Variables dialog, click Import from File.


1 Answers

Don't use env; use declare -px, which outputs the values of exported variables in a form that can be re-executed.

$ declare -px > env.sh
$ source env.sh

This also gives you the possibility of saving non-exported variables as well, which env does not have access to: just use declare -p (dropping the -x option).


For example, if you wrote foo=$'hello\nworld', env produces the output

foo=hello
world

while declare -px produces the output

declare -x foo="hello
world"
like image 150
chepner Avatar answered Oct 07 '22 13:10

chepner