Query Environment Variable in a DOS Script

Posted on 2005-05-03
Last Modified: 2006-11-18
okay, i probably knew this one 20 years ago but my brain is now fogged ...

I have a simple DOS script:

IF  my_environment_variable == 1 then a.bat ELSE b.bat

and its failing the test for equal to 1;  I've tried "1" and '1' with no luck.  

how do I make this work?
Question by:jmorgie
    1 Comment
    LVL 30

    Accepted Solution

    Do this:

    @echo off

    if "%EnvVar%"=="1" (
      echo EnvVar is 1
    ) else (
      echo EndVar is not 1

    Good Luck,

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Join & Write a Comment

    Using dates in 'DOS' batch files has always been tricky as it has no built in ways of extracting date information.  There are many tricks using string manipulation to pull out parts of the %date% variable or output of the date /t command but these r…
    YESTERDAY YESTERDAY.BAT is inspired by a previous article I wrote entitled: TOMORROW.BAT ( The crux of this batch f…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now