1

How can I echo a string that contains a colon :?

I know from http://www.robvanderwoude.com/escapechars.php that most characters can be escaped using ^, but that won't work for a colon IF it is precededby %0%


I have a batch file x.bat that contains

echo %0% http://blank

When run as x.bat it gives me:

x.bat//blank

I want it to print out

x.bat http://blank

How to do this?

parvus
  • 5,706
  • 6
  • 36
  • 62
  • 1
    Well done stripping the problem down to the least amount of code required to reproduce the failure. It's nice not to have to read all day to figure out what's bugging someone. – rojo Dec 22 '14 at 16:31

1 Answers1

2

you have a syntax problem. The filename of the batchfile is %0, not %0%:

echo %0 http://blank 
Stephan
  • 53,940
  • 10
  • 58
  • 91
  • 2
    Yes, `%0` expands to `x.bat`, and `% http:` is a failed expansion that becomes an empty string. The behavior is described at http://stackoverflow.com/a/7970912/1012053 – dbenham Dec 22 '14 at 16:33
  • The batch rules are a monstrosity. Thank you both; for spotting my error this fast, and for the helpful link. – parvus Dec 23 '14 at 08:16