save & restore environment (Developers)
I ran into a situation in SvarDOS where the EDR-DOS command interpreter was creating duplicate environment variables. For example, when i ran the SET command, i might see multiple PATH= variables in its output. I believe it was related to running out of space in the environment. The way i worked around this problem was by increasing the size of the environment, and also by running COMMAND /C instead of CALL to run helper .bat files. With COMMAND /C the original environment is restored when the helper .bat file completes.
I found myself wishing for a utility to back up and restore the environment. As an exercise, i wrote a couple of AWK scripts to do it.
mkenvset.awk
# Usage: awk -f mkenvset.awk >envset.bat
# Run envset.bat to restore all environment variables
BEGIN {
for (k in ENVIRON) {
printf "SET %s=%s\n", k, ENVIRON[k]
}
}
mkenvdel.awk
# Usage: awk -f mkenvdel.awk >envdel.bat
# Run envdel.bat to delete all environment variables
BEGIN {
for (k in ENVIRON) {
printf "SET %s=\n", k
}
}
I imagine using them like so:
awk -f mkenvset.awk >envset.bat
call helper.bat
awk -f mkenvdel.awk >envdel.bat
call envdel.bat
call envset.bat
This would effectively restore the original environment without using a COMMAND /C sub-shell.
What do you think? Is it a bad idea? Why?
Complete thread:
- save & restore environment - bencollver, 28.02.2026, 00:52 (Developers)
![Open in board view [Board]](img/board_d.gif)
![Open in mix view [Mix]](img/mix_d.gif)
- save & restore environment - Rugxulo, 28.02.2026, 03:18
- save & restore environment - bencollver, 28.02.2026, 04:26
- save & restore environment - Rugxulo, 01.03.2026, 00:24
- save & restore environment - bencollver, 28.02.2026, 04:26
- save & restore environment - boeckmann, 28.02.2026, 10:23
- save & restore environment - bencollver, 28.02.2026, 15:20
- save & restore environment - boeckmann, 28.02.2026, 19:26
- save & restore environment - bencollver, 01.03.2026, 15:12
- save & restore environment - bencollver, 08.03.2026, 00:45
- save & restore environment - jadoxa, 08.03.2026, 01:39
- save & restore environment - bencollver, 08.03.2026, 02:05
- save & restore environment - boeckmann, 08.03.2026, 22:23
- save & restore environment - boeckmann, 09.03.2026, 17:15
- save & restore environment - bencollver, 09.03.2026, 20:09
- save & restore environment - boeckmann, 09.03.2026, 17:15
- save & restore environment - boeckmann, 08.03.2026, 22:23
- save & restore environment - bencollver, 08.03.2026, 02:05
- save & restore environment - jadoxa, 08.03.2026, 01:39
- save & restore environment - boeckmann, 28.02.2026, 19:26
- save & restore environment - bencollver, 28.02.2026, 15:20
- save & restore environment - Rugxulo, 28.02.2026, 03:18
Mix view