orshachar
orshachar

Reputation: 5037

BATCH: How to echo string containing '&' char to a file

I'm trying to write to a file a URL string that has the '&' char in it (using simple 'echo'), problem is that it's a saved char in the command prompt so it fails.

Is there any way to tell the command prompt that it's part of the string.

Example:

echo www.google.com/search=make&peace > love.txt

I'll get an error indicating that "peace" is not a recognized command.

Thanks!

Upvotes: 5

Views: 30663

Answers (2)

rkokkelk
rkokkelk

Reputation: 144

Just enclose the URL in Quotes:

echo "www.google.com/search=make&peace" > love.txt

Upvotes: 4

Cat Plus Plus
Cat Plus Plus

Reputation: 130004

cmd uses ^ as the escape character, so

echo www.google.com/search=make^&peace > love.txt

Upvotes: 20

Related Questions