Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 102023
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T00:53:02+00:00 2026-05-11T00:53:02+00:00

Having read an existing post on stackoverflow and done some reading around on the

  • 0

Having read an existing post on stackoverflow and done some reading around on the net. I thought it was time to post my question before I lost too much hair!

I have the following code within a batch file which I double click to run, under Windows XP SP3:

SETLOCAL ENABLEDELAYEDEXPANSION  ::Observe variable is not defined SET test  ::Define initial value SET test = 'Two'  ::Observe initial value is set SET test  ::Verify if the contents of the variable matches our condition If '!test!' == 'Two' GOTO TWO  ::First Place holder :ONE  ::Echo first response ECHO 'One'  ::Second Place holder :TWO  ::Echo second response ECHO 'Two'  ::Await user input PAUSE  ENDLOCAL 

Basically I am trying to establish if I can navigate through my script using conditionals. It seems apparent that I am getting some issues with variable scope and delayed variable expansion yet I’m a little lost on what I’m doing wrong.

Can anyone point me in the right direction?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T00:53:02+00:00Added an answer on May 11, 2026 at 12:53 am

    Your immediate problem is that you’re setting the variable to the value < ‘Two’> which you can see here:

    @echo off  SETLOCAL ENABLEDELAYEDEXPANSION  ::Observe variable is not defined SET test  ::Define initial value SET test = 'Two'  ::Observe initial value is set SET test echo %test% echo..%test %.  ::Verify if the contents of the variable matches our condition If '!test!' == 'Two' GOTO TWO  ::First Place holder :ONE  ::Echo first response ECHO 'One'  ::Second Place holder :TWO  ::Echo second response ECHO 'Two'  ::Await user input PAUSE  ENDLOCAL 

    which produces:

    Environment variable test not defined test = 'Two' . 'Two'. 'One' 'Two' Press any key to continue . . . 

    The reason your ‘set test’ is outputting the variable is the same reason why ‘set t’ would – if there’s no variable of the specific name, it outputs all variables starting with that name.

    The set command is also a finicky little beast and does not like spaces surrounding the ‘=’ characters; it incorporates them (and the quotes by the way) into the environment variable name and the value assigned to it. Instead, use:

    set test=Two 

    Also, where you’re using delayed expansion, it doesn’t matter since %test% and !test! would expand the same. It’s useful in statements like:

    if '!test!' == 'Two' (     set test=TwoAndABit     echo !test! ) 

    The inner echo will output TwoAndABit whereas %test%, which is expanded when the whole if-statement is encountered, would cause it to output Two.

    Still, I always use delayed expansion everywhere just for consistency.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 86k
  • Answers 86k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Some folk have posted that @@IDENTITY would be fast, so… May 11, 2026 at 5:19 pm
  • Editorial Team
    Editorial Team added an answer Yes, you need to specify a type parameter when you… May 11, 2026 at 5:19 pm
  • Editorial Team
    Editorial Team added an answer It's O(1). You can google for the source code and… May 11, 2026 at 5:19 pm

Related Questions

I've read a lot of times that one should never blindly catch exceptions. Some
I have an Action method in an ASP.NET MVC Controller class that handles form
I've added a reference to a co-worker's COM DLL -- MyLogic.dll -- to my
Is there an easy way in C# to read a properties file that has

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.