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 9141421
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:38:32+00:00 2026-06-17T09:38:32+00:00

I am writing a batch file where I need to output a string containing

  • 0

I am writing a batch file where I need to output a string containing ‘!’ to another file. But when I echo that string to another file, it removes “!” from the output.

Eg:
Input:

set LINE=Hi this is! output
echo !LINE!>>new_file.txt

Output in new_file.txt is:

Hi this is output

Also, if input is

set LINE=Hello!! this is output!!
echo !LINE!>>new_file.txt

Output in new_file.txt:

Hello

Hence, it skips the ! (Exclamation mark) from the output to the new_file.
If I use %LINE%, then it simply displays “echo is on” to the output file.

Please suggest a way to overcome this problem.

  • 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-06-17T09:38:33+00:00Added an answer on June 17, 2026 at 9:38 am

    If you have delayed expansion enabled and want to output an exclamation mark, you need to escape it.

    Escaping of exclamation marks needs none, one or two carets, depending on the placement.

    @echo off
    REM No escaping required, if delayed expansion is disabled
    set test1=Test1!
    
    setlocal EnableDelayedExpansion
    REM One caret required
    REM Delayed expansion uses carets independent of quotes to escape the exclamation mark
    set "test2=Test2^!"
    
    REM Two carets required
    REM The first caret escapes the second caret in phase2 of the parser
    REM Later in the delayed expansion phase, the remaining caret escapes the exclamation mark
    set test3=Test3^^!
    
    
    echo !test1!
    echo !test2!
    echo !test3!
    

    The difference between !var! and %var% in blocks is explained at DOS batch: Why are my set commands resulting in nothing getting stored?

    An explanation of the batch parser can be found at How does the Windows Command Interpreter (CMD.EXE) parse scripts?

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

Sidebar

Related Questions

I need some help in writing a batch file; it launches another application which
I'm new to Windows batch files, but I'm writing a .bat file that just
I have a variable define as: set filePath=.\file.txt I'm writing a windows batch file.
I am writing a batch file where I need to list all the directories
I'm writing a batch file and I need to know if a file is
I am writing a batch file that will generate/write to a property file based
I am writing a batch file that does a number of operations in a
Hey, I'm having some problems writing a batch file where I need to specify
I need some help in writing a batch file. I have a path stored
I'm writing a batch file which is supposed (among other things) to call another

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.