15 ms·
I have been revisiting the DOS eco-system lately and I have run into a problem. I can't remember how to ECHO a variable set in AUTOEXEC.BAT. E.g, to ECHO the BL
by pan69 6y ago
I have been revisiting the DOS eco-system lately and I have run into a problem. I can't remember how to ECHO a variable set in AUTOEXEC.BAT. E.g, to ECHO the BLASTER variable, I've tried ECHO BLASTER, ECHO $BLASTER, ECHO $BLASTER$, ECHO %BLASTER, etc.. But nothing. Somehow a Google search didn't turn up anything. I'm starting to wonder if it was it even possible to do this and that my memory is incorrect?
Cool list by the way. Bookmarked!
- skissane 6y agoECHO %BLASTER% You almost had it, you just need two percents. It is the same syntax as Windows cmd.exe currently uses
- pan69 6y agoOK, so I tried this, but ECHO %PATH% just outputs %PATH%. I'm running DOS 6.22 on a 286. Same thing happens for any other variable defined in AUTOEXEC...
- morsch 6y ago"In DOS I believe that %var% expansion only works in batch files, not at the command line directly."[1] That worked for me in an emulator.[2] [1] https://stackoverflow.com/questions/28021862/echo-variable-shows-variable-in-ms-dos-6-22 https://stackoverflow.com/questions/28021862/echo-variable-s... [2] https://jamesfriend.com.au/pce-js/ibmpc-games/ https://jamesfriend.com.au/pce-js/ibmpc-games/
- pan69 6y agoConfirmed. It doesn't work directly from the prompt, only within a batch file. I think might work on a DOS 7 prompt (Win95 >) though, not sure, I don't have a Windows machine hooked up atm. Maybe that's where my memory is from... Thanks!
- jimmyswimmy 6y agoIt was % to indicate environment variables. echo %PATH% Should work, as long as that variable is in scope, which it should be on an old MSDOS platform with a single thread.
- TeMPOraL 6y agoEnvironmental variables have scopes?
- pan69 6y agoIts probably that variables defined in AUTOEXEC are "global" scope, i.e. can be referenced in any other batch file, but variables defined within a batch file other than AUTOEXEC only exist within the scope (context) of that batch file. But, I haven't tested this...
- 4cao 6y agoI think in DOS they were all global in scope. SETLOCAL appeared with Windows NT (cmd.exe), not sure which version (I didn't use the early ones).
- brirec 6y agoSET BLASTER No “=” — `SET BLASTER=` will erase the variable, and of course `SET BLASTER=f00` will set it to “f00”. N.b., `SET FOO` will display all variables beginning with “FOO” and remember that DOS/Windows vars aren’t case sensitive.