Charles Dye
Super Moderator
- May
- 5,357
- 163
Staff member
Since time immemorial, the help file has offered this advice:
This is (a) peculiar syntax in both shells and (b) not foolproof -- @EVAL's return value is affected by SETDOS /F. Also, the "loaded" terminology is a throwback to DOS days. I would suggest instead something like this:
From a batch file, you can determine if <shell> is loaded by testing for the variable function @EVAL, with a test like this:
if "%@eval[2 + 2]%" == "4" echo <shell> is loaded!
This is (a) peculiar syntax in both shells and (b) not foolproof -- @EVAL's return value is affected by SETDOS /F. Also, the "loaded" terminology is a throwback to DOS days. I would suggest instead something like this:
A batch file can test whether it is running in TCC by attempting a numeric comparison:
if 01 == 1 echo Running in TCC!
This syntax is legal in both shells. In TCC this is a numeric comparison and true; in CMD.EXE it is a string comparison and false. Once you have established that the batch file is running in TCC, you can use internal variables like _CMDPROC, _4VER, _DOS, _DOSVER, and _WIN to further determine the operating environment.
You can prevent your batch file from running in CMD.EXE by giving it the .BTM extension. CMD.EXE doesn't recognize .BTM files as batch files.