set var=%1
echo var
set command=""
IF var==true (
set command=dir
)
IF var==false (
set command=dir /a
)
echo %command%
%command%
So, if I run this script by typing in
C:\>test true
the echo %command% always prints "". Any idea?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You are missing some
%signs that are needed for any variable dereferencing.You probably want it like this:
You should also surround your string comparisons with quotes to allow for spaces, something like this:
Also, as Joey pointed out, clearing a variable is done by
without any quotes. Otherwise you will initialize the the variable with these quotes, leading to your weird output.