On windows/cygwin, i want to be able save the PATH variable to file on one machine and load it onto the other machine;
for storing the variable i am doing:
echo %PATH% > dat however, not sure how to load it later.
set PATH=??????? Thanks Rami
Just use: set /P PATH=< dat
You must note that echo %PATH% > dat insert an additional space after %PATH% value; that space may cause problems if an additional path is later added to PATH variable. Just eliminate the extra space this way: echo %PATH%> dat.
set /P can only read 1024 characters. To read more, use for /F as shown in SpaceMonkey answer below.This might be evil but on Windows I am using this:
for /F %%g in (dat) do set PATH=%%g and this to write the file because I had trouble with spaces
echo>dat %PATH% Being dependent upon Cygwin, how how about putting the command in your saved file, e.g.:
echo "export PATH=$PATH" > dat Then sourcing the script later to set the path:
. ./dat Note that "sourcing" the script (vs. just executing it) is required for it to modify your current environment - and not just new child environments.
The following sample works even with spaces and dot in the path value:
@REM Backup PATH variable value in a file @REM Set PATHBACKUP variable with value in the file @echo %PATH% > pathvalue.txt @type pathvalue.txt @for /f "delims=" %%l in (pathvalue.txt) do ( @set line=%%l ) @set PATHBACKUP=%line% @echo %PATHBACKUP%
set /P PATH=< dat