The following achieves double dereferencing:
deref.cpp
#include <stdio.h>
#include <stdlib.h>
void explain()
{ fputs("deref variable\n"
" Dereference a windows variable\n", stderr);
}
int main(int argc, char **argv)
{ if (argc <= 1 || argv[1][0] == '-' || argv[1][0] == '?')
explain();
char * dir = getenv(argv[1]);
if (dir)
fputs(dir, stdout);
return 0;
}
cdd.bat
@echo off
if "%1" == "" (
set t=%cd%
set vv=%t:^\=/%
echo %vv:^"=%
) else (
if "%1" == "-" (
cd %lastdir%
) else (
set lastdir=%cd%
for /f %%a in ('where %0') do set here=%%~dpa
for /f %%a in ('%here%deref %1') do set tgt=cd %%a
call %tgt%
)
)
Question:
Is there a way to do this without using the program deref.cpp?
Is there a way to do it using only the best programming language in the world? :)
It has been claimed that this is relevant to the question (but it is not)
Variables are not behaving as expected
When uploading the cdd.bat code one has to be very careful about spaces as .bat language is very sensitive to these.