Nested Environment Variables
The following workaround example shows how to nest environment variables inside of each other in a batch file. The nested variables can be used for specifying sub-string indices or replacements dynamically during runtime.
For example to remove the current directory from the path environment variable:
set path=%PATH:%CD%=%
does not work. However, the following code:
for /f "delims=" %%i in ('echo %%PATH:%CD%^=%%') do set path=%%i
will work fine.
References
- Veli-Pekka Tätilä's A Modern Batch Programming Tutorial introduced the problem.
- Mac's hint in Getting hold of the current directory in a batch file clued me into the technique.
No comments:
Post a Comment