eTechtips

Tech Tips and Insights

DOS: Check for empty environment variable

I was writing a batch file the other day and needed to change the argumets to a command based on if the user had specified his password on the command line.

SET PASS=somepassword
: or
:SET PASS=
if x%PASS%= X (
  SET PASSARG=--password somepassword
) else
(
  SET PASSARG=
)

commandtorun %PASSARG%

Now if the user comments out his password, the script will make the PASSARG environment variable be empty or if they set a password the passarg variable will be filled in.

Loading

0 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.