save & restore environment (Developers)
> 4DOS and NT's CMD both have "SETLOCAL". So if you don't need any vars to
> persist, try that.
Thanks for that information. 4DOS is really "where it's at" isn't it?
> If you insist on this way (presumably to run on older shells), I'd suggest
> putting it in a single .BAT like "SAVEENV.BAT [on | off]". The AWK scripts
> are small enough to be in-place, but even an embedded AWK script (or ten)
> is easy to use.
Here's an attempt at SAVEENV.BAT:
@echo off
if x%1 == xon goto save
if x%1 == xoff goto restore
goto usage
:usage
echo SAVEENV.BAT ON
echo This saves the environment.
echo.
echo SAVEENV.BAT OFF
echo This restores the saved environment.
echo.
goto the_end
:save
echo BEGIN{ >%TEMP%\envset.awk
echo print "@echo off" >>%TEMP%\envset.awk
echo for(k in ENVIRON){printf "SET %%s=%%s\n",k,ENVIRON[k]} >>%TEMP%\envset.awk
echo } >>%TEMP%\envset.awk
awk -f %TEMP%\envset.awk >%TEMP%\envset.bat
goto the_end
:restore
echo BEGIN{ >%TEMP%\envdel.awk
echo print "@echo off" >>%TEMP%\envdel.awk
echo for(k in ENVIRON){printf "SET %%s=\n",k} >>%TEMP%\envdel.awk
echo } >>%TEMP%\envdel.awk
awk -f %TEMP%\envdel.awk >%TEMP%\envdel.bat
call %TEMP%\envdel.bat
call %TEMP%\envset.bat
goto the_end
:the_end
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