computing
  • 0

[Batch] Test For Empty Variable

  • 0

if “%var%”==”” echo empty

nothing

echo %var% >gives> %var%

which is probably why. any ideas people?

Share

1 Answer

  1. my quite non-brilliant analysis is:
    1) assuming you have set a value for %var%
    echoing that value to that value will result in a file, not a variable.
    f/e: set %var%=im_ok
    echo %var% > gives > %var%
    sends the string, “im_ok” to the line one of the file “im_ok”, and not to
    a variable %var%.
    2) Also, the intermediate pipe doesn’t really
    do anything ( > gives > ). That file is not created, or not as a
    persistant entity.
    ultimately, the variable’s value is reflected in a file having the
    name that is the variable’s value. The value does not wind up
    back in the variable. It’s in the file that has the variable’s contents as its name.
    (f/e: you can: set aa=TEST
    but you can’t: echo TEST > %aa% except %aa% is a file not a var. No reason to anyway.)
    Maybe post a synopsis of what you’re trying to accomplish might get some real help as opposed to this non-help. 🙂

    ps: sorry, just re-read my post.
    It IS saturday night, I HAVE consumed alc.
    beverages. apologies! Lol!

    • 0