# How to save multiple expression in a single file with specified names for the expressions

I could not find any reasonable answer for the following question. (https://www.physicsforums.com/threads/mathematica-output-display.386890/).

I have expressions:

f1=1;
f2=20;


I want to save them in a single file:

PutAppend[f1,f2,"output.m"];


This prints all the expression in the output file. The output of this is:

cat output.m
1
20


However I was wondering is there any way to print (save) the variable name as well or any customised name. The desired output:

f1=1
f2=20


or

name1=1
name2=20


I tried some but those are not useful.

foo = {"test"};
bar = Association[];
Save["test.m", {foo, bar}]
FilePrint["test.m"]

foo = {"test"}

bar = <||>


You can Get the symbols back to the current namespace after you have restarted the Kernel or have just removed them once:

ClearAll["Global*"]
foo
bar
Get["test.m"]
foo
bar

foo

bar

<||>

{"test"}

<||>
`
• This helps. Save["output.m",f1,f2] will give the desired output, however without customization of the name at the time of printing/saving. Of course one can always change the expression name f1-> name1 and f2-> name2. – Boogeyman Sep 7 '18 at 16:04