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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T07:11:26+00:00 2026-06-12T07:11:26+00:00

Here’s a simple bat file: C:\temp>type a.bat @echo off rem try echo %1 With

  • 0

Here’s a simple bat file:

C:\temp>type a.bat
@echo off
rem try
echo %1

With some difficulty, I am able to pass a&b as parameter to it:

C:\temp>a.bat a&b
a
'b' is not recognized as an internal or external command,
operable program or batch file.
C:\temp>a.bat "a&b"
"a&b"

The paramater has the " character; I can live with it. But I can’t figure out how to call it from a cygwin shell:

C:\temp>c:\cygwin\bin\sh
sh-4.1$ ./a.bat a&b
[1] 7760
a
sh: b: command not found
sh-4.1$ ./a.bat a\&b
a
'b' is not recognized as an internal or external command,
operable program or batch file.
[1]+  Done                    ./a.bat a
sh-4.1$ ./a.bat \"a\&b\"
"\"a
'b\""' is not recognized as an internal or external command,
operable program or batch file.
sh-4.1$ ./a.bat "a\&b"
a\
'b' is not recognized as an internal or external command,
operable program or batch file.
  • 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-12T07:11:28+00:00Added an answer on June 12, 2026 at 7:11 am

    Windows CMD uses ^ to escape most special characters. So you can use that to pass your argument without enclosing quotes.

    C:\temp>a.bat a^&b
    

    But the parameter that is received will be a&b. Your batch script will give an error when it attempts to ECHO the value of %1 because the & is not quoted or escaped.

    You could safely echo the value if you enclose it in quotes:

    echo "%1"
    

    But if you pass the value already enclosed in quotes "a&b", then you get an error again. That is why many batch script use the ~ modifier to remove any existing enclosing quotes (if they exist), and then explicitly add quotes. The following will work if the value of %1 is quoted or unquoted.

    echo "%~1"
    

    You still can have problems with something like "a&b"&c, but that is another story 🙂

    Another option would be to double escape the & in the original command line:

    C:\temp>a.bat a^^^&b
    

    Your batch script will recieve a^&b, and then the echo will work.

    With regard to Cygwin, I know very little, but I believe I mostly understand tests 1, 2 and 3.

    Test 1:

    sh-4.1$ ./a.bat a&b
    [1] 7760
    a
    sh: b: command not found
    

    Cygwin is passing a to your batch script and failing to execute command b

    Test 2:

    sh-4.1$ ./a.bat a\&b
    a
    'b' is not recognized as an internal or external command, operable program or batch file.
    

    I’m not sure if CMD parses the command line passed from Cygwin before the batch script is executed or not.

    If so, then a is getting passed to your batch script, and then CMD.EXE is failing to execute b.

    If not, then Cygwin is successfully executing your script and passing a&b, but your ECHO statement is failing as I explained earlier.

    One of the following should work with your script, but I’m not sure which:

    sh-4.1$ ./a.bat a^\&b
    or
    sh-4.1$ ./a.bat a^^^\&b
    

    One of the above will pass a^&b and your ECHO should work.

    Test 3:

    sh-4.1$ ./a.bat \"a\&b\"
    "\"a
    'b\""' is not recognized as an internal or external command, operable program or batch file.
    

    I have no idea what Cygwin is doing. Somehow it is introducing additional double quotes.

    Test 4:

    sh-4.1$ ./a.bat "a\&b"
    a\
    'b' is not recognized as an internal or external command, operable program or batch file.
    

    Cygwin strips the quotes, and the backslash is preserved. Again, either the & is causing problems when CMD.EXE is launching the script, or it is causing problems within the script when you ECHO it.

    One of the following should work, passing a^&b to your script. I’m just not sure which one:

    sh-4.1$ ./a.bat "a^&b"
    or
    sh-4.1$ ./a.bat "a^^^&b"
    

    I believe the following will successfully pass "a&b" to your script:

    sh-4.1$ ./a.bat '"a&b"'
    

    I also think the following will do the same, though I am not as confident due to the result of Test 3.

    sh-4.1$ ./a.bat "\"a&b\""
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
Here is a simple timepicker to jQuery UI's datepicker <script type=text/javascript> /* <![CDATA[ */
Here a simple question : What do you think of code which use try
Here's my code in the <head></head> : <link rel=stylesheet href=http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.css /> <script type=text/javascript src=http://code.jquery.com/jquery-1.7.1.min.js></script>
Here is what I am currently doing. PHP echo's out the recent post in
Here is the Javascript I currently have <script type=text/javascript> $(function() { $('.slideshow').hover( function() {
Here is the script I'm using, copied directly from Google: <script type=text/javascript> var _gaq
Here is an example: I have the generic type called Account. I wish to
Here's what I'm doing. I want to upload multipart file via Ajax to my
//here is my code public void performSearch() throws Exception { try { System.out.println(Perform Search

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.