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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T15:16:57+00:00 2026-05-31T15:16:57+00:00

I’m trying to echo a string stored in a variable but it seems to

  • 0

I’m trying to echo a string stored in a variable but it seems to require a lot of escaping. I’m trying with the following code:

setlocal EnableDelayedExpansion
@echo off
set "grass=@##&!$^&%**(&)"
echo !grass!

I want to echo the variable grass verbatim so I see a @##&!$^&%**(&) in the output. What should be done? Thanks!

  • 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-31T15:16:59+00:00Added an answer on May 31, 2026 at 3:16 pm

    echo !grass! will always echo the current value verbatim, without the need of any escaping. Your problem is, the value is not what you think it is! The problem is occurring when you are trying to SET the value.

    The correct escape sequence to set your value is

    set "grass=@##&^!$^^&%%**(&)"
    

    And now for the explanation. The information you need is buried in How does the Windows Command Interpreter (CMD.EXE) parse scripts?. But it is a bit hard to follow.

    You have two problems:

    1) % must be escaped as %% for each time the line will be parsed. The presence or absence of quotes makes no difference. The delayed expansion state also makes no difference.

     set pct=%
     :: pct is undefined
    
     set pct=%%
     :: pct=%
    
     call set pct=%%
     :: pct is undefined because the line is parsed twice due to CALL
    
     call set pct=%%%%
     :: pct=%
    

    2) A ! literal must be escaped as ^! whenever it is parsed by the delayed expansion phase of the parser. If a line contains ! anywhere within it during delayed expansion, then a ^ literal must be escaped as ^^. But the ^ must also be either quoted or escaped as ^^ for the special character phase of the parser. This can be further complicated by the fact that a CALL will double up any ^ characters. (Sorry, it is very difficult to describe the problem, and the parser is complicated!)

    setlocal disableDelayedExpansion
    
    set test=^^
    :: test=^
    
    set "test=^"
    :: test=^
    
    call set test=^^
    :: test=^
    :: 1st pass - ^^ becomes ^
    :: CALL doubles ^, so we are back to ^^
    :: 2nd pass - ^^ becomes ^
    
    call set "test=^"
    :: test=^^ because of CALL doubling. There is nothing that can prevent this.
    
    set "test=^...!"
    :: test=^...!
    :: ! has no impact on ^ when delayed expansion is disabled
    
    setlocal enableDelayedExpansion
    
    set "test=^"
    :: test=^
    :: There is no ! on the line, so no need to escape the quoted ^.
    
    set "test=^!"
    :: test=!
    
    set test=^^!
    :: test=!
    :: ! must be escaped, and then the unquoted escape must be escaped
    
    set var=hello
    set "test=!var! ^^ ^!"
    :: test=hello ^ !
    :: quoted ^ literal must be escaped because ! appears in line
    
    set test=!var! ^^^^ ^^!
    :: test=hello ^ !
    :: The unquoted escape for the ^ literal must itself be escaped
    :: The same is true for the ! literal
    
    call set test=!var! ^^^^ ^^!
    :: test=hello ^ !
    :: Delayed expansion phase occurs in the 1st pass only
    :: CALL doubling protects the unquoted ^ literal in the 2nd pass
    
    call set "test=!var! ^^ ^!"
    :: test=hello ^^ !
    :: Again, there is no way to prevent the doubling of the quoted ^ literal
    :: when it is passed through CALL
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace

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.