Ampersand in Environment Variables

J

jgreinecke

Hello all,


I'm using WinXP ver 5.1.2600 (at least 'ver' tells me so)
and try to create an environmental variable whose value
contains an ampersand (&) (like at&t)

The MS Product Documentation tells me:
... If you use the special characters <, >, |, &, or ^, you
must precede them with the escape character (^) or quotation
marks
...

To create the variable value new&name, type:
set varname=new^&name

However when I tried this :
set prv=at^&t
echo %prv%

The response was:
-> at
-> 't' not recognized as program... etc.',

That is, XP was looking for an executable named 't' which
wasn't there.

Even more puzzling, the following command worked fine:
set dmy=^&(dummy^)
echo %dmy%
-> (dummy).

Hence my question: Why did the escape character work in front
of parentheses, and did not work in front of the ampersand?


Any help welcome!


Jürgen
 
D

David Candy

Don't echo it. & means a seperator between commands. When you echo

echo at
& meaning new command
t

use Set A to display it.

It is working. What is happening is with the expansion.

Try AT^^^&T

which will put AT^&T into Prv which when expanded will show as AT&T, escaping it on expansion.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top