Page 1 of 1

Save/Load null variables

Posted: 15 Feb 2019 13:39
by EliJamesMorey
Is there any way to save null variables I have been saving and loading variables using.

(
echo %variable%
echo %variable2%
echo %variable3%
)>save.sav

and

(
set /p variable=
set /p variable2=
set /p variable3=
)<save.sav

This works fine, except that some variables are null (and I would like to keep them that way), and when
they have been saved and loaded, then they always show up as "ECHO is off." rather than just a blank.

What can I do to fix this? I want null variables to continue appearing as blank spaces even after loading.

Thanks in advance for your help.

Re: Save/Load null variables

Posted: 15 Feb 2019 13:58
by Squashman

Code: Select all

@echo off
set "variable=var1"
set "variable2="
set "variable3=var3"

(
echo.%variable%
echo.%variable2%
echo.%variable3%
)>save.sav

(
set /p variable=
set /p variable2=
set /p variable3=
)<save.sav

echo.%variable%
echo.%variable2%
echo.%variable3%

Pause

Re: Save/Load null variables

Posted: 15 Feb 2019 14:01
by aGerman
some variables are null
I assume they are not defined. In that case you want to write an empty line into your file.

Code: Select all

(
  echo(%variable%
  echo(%variable2%
  echo(%variable3%
)>"save.sav"
Steffen

Re: Save/Load null variables

Posted: 16 Feb 2019 10:19
by Ed Dyreen
some variables are null
NULL does exist as character but is used internally by cmd for delimiting variables in memory and cannot be assigned or it is used in the context of device during a redirection.