I want to export some environment variables which I set in a dash script to a file:
myvariable="line 1
LINE=3
some characters: # \" \$
line 5"
myvariable2="abc"
export myvariable myvariable2
expected result (a usable script):
declare -x myvariable="line 1
LINE=3
some characters: # \" \$
line 5"
declare -x myvariable2="abc"
The result is what I get using the export command. But it exports all envvars and doesn't allow filtering. Because of the multi-line character of the variable, greping the result is not possible.
In contrast, the printenv command allow to output only a selection of variables, but it doesn't care about escaping and it doesn't output the variable names in this use case.
exportandprintenvare both returning your variables as you defined them. Did you want newlines to be converted to something else?printenvwill create garbage,printenv myvariable myvariable2doesn't output a script, export exports the full environment includingPATHetc and not onlymyvariableandmyvariable2