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

  • SEARCH
  • Home
  • 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 6738275
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:20:53+00:00 2026-05-26T11:20:53+00:00

Running this batch file @echo off set a=some value with (parentheses) inside if 1

  • 0

Running this batch file

@echo off
set a=some value with (parentheses) inside
if 1 == 1 (
    set PATH=%a%
)

gives inside was unexpected at this time. error.

How to escape a variable to avoid this error?

  • 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. Editorial Team
    Editorial Team
    2026-05-26T11:20:53+00:00Added an answer on May 26, 2026 at 11:20 am

    You can use two different ways

    Use the extended syntax of set with quotes set "var=content" will set var with content,
    content is quoted so special characters aren’t problematic and it uses the content till the last quote (without the quote itself)

    @echo off
    set a=some value with (parentheses) inside
    if 1 == 1 (
        set "PATH=%a%"
    )
    

    Use delayed expansion (like the answer of shf301) but also transfer the value to the main scope.

    @echo off
    setlocal enabledelayedexpansion
    set a=some value with (parentheses) inside
    if 1 == 1 (
        set "localScope_PATH=!a!"
        rem now transfer it to the global scope
        FOR /F "delims=" %%A in ("!localScope_PATH!") DO (
           endlocal
           set "path=%%A"
        )
    )
    

    In this case the extended set-syntax is not necessary, I used it only to avoid hidden spaces at the line end.

    EDIT:
    Can I combine this with setlocal EnableDelayedExpansion and using ! instead of % to lazy evaluate variable’s value? When I tried I got )! was unexpected at this time.

    You can, but it’s contra productive, as

    @echo off
    Setlocal EnableDelayedExpansion
    set a=some value with (parentheses) inside
    if 1 == 1 (
        set PATH=!a:^)=^^^)!
        set path
    )
    

    Then your path contains carets in front of the ) like
    C:\programs (x86^)

    To understand how expansion works you can read SO:How does the Windows Command Interpreter (CMD.EXE) parse scripts?

    EDIT2: More problems with the path (containing quotes)
    According to this question there can occour another problem with parenthesis when the path contains quotes.

    Sample
    path="C:\Program Files (x86)";C:\Program Files (x86)\Skype

    This is allowed, even it’s not necessary to use quotes here, but this destroys the extended SET syntax, as now set "newPath=%path%" expands to

    set "newPath="C:\Program Files (x86)";C:\Program Files (x86)\Skype"
    

    Now at least one parenthesis is not inside quotes and is able to break a command block.

    But you can simply remove all quotes from the path variable, as said, quotes aren’t necessary here.

    set "newPath=%path:"=%"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a batch file in Windows. Here is my .bat file @echo off
I have a simple batch file like this: echo off taskkill /im test.exe /f
I'm running this small C# test program launched from a pre-commit batch file private
I'm running a batch file on Windows and got this error: The syntax of
Running the following example batch file, echo foo &&^ C:Program FilesInternet Exploreriexplore.exe ...produces the
This is a very specific question, however; Say I have a batch file running
I'm running a batch file from some ASP.NET/C# code on a web server. Basically
I'm running this command on a batch file: for %I in (*.txt *.doc) do
I'm trying to run this batch file from a windows service (running as my
Is there a way for a batch file (in this case, running on Windows

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.