none
Using variables in user input - batch file RRS feed

  • Question

  • I am working with a batch script that I am making. It receives user input and runs a command based on that. If the user inputs a variable (e.g. %HOMEDRIVE%) it treats it like a string and not a variable. Any idea why?

    Here is a basic example:

    @ECHO OFF
    @CLS
    :CMD
    @ECHO.
    @SET /P "COMMAND=>"
    @ECHO %COMMAND%
    @GOTO CMD

    Use it to create a batch file and try using the echo command to test using variables. Having SETLOCAL EnableDelayedExpansion allows for variables in the exclamation mark format (e.g. !HOMEDRIVE!). But with or without it, the percent format does not work.

    Please understand that I am not saying that variables within the script are not working but that variables inserted by the user when the script is run are not working.

    • Moved by Bill_Stewart Monday, March 12, 2018 8:40 PM This is not "fix/debug/rewrite my script for me" forum
    Wednesday, January 24, 2018 2:02 PM

All replies