10

whats the easiest way of converting all backslashes to forward in a path in a batch file, since I need to use bash for execution.

remo
  • 3,326
  • 6
  • 32
  • 50
  • ... Wich one is it? Batch or Bash? Batch is for Windows, Bash is for Linux (and Mac?). – RobinJ May 31 '11 at 15:19
  • I am running batch(windows), need to build a make file using Bash( on windows, i have bash set up on the machine) – remo May 31 '11 at 15:20
  • Ah, something lik Win-Bash, I presume? So... You want to read a file (using MS-DOS Batch), and replace all occurances of \ to /. Is that correct? – RobinJ May 31 '11 at 15:22

2 Answers2

26
SET "string=D:\path\to\folder"
ECHO %string:\=/%

Basically, you need first to store the string value into an environment variable, then use the following template:

%variable:str1=str2%

to replace every occurrence of str1 in variable with str2.

You can always remind yourself about this pattern by invoking SET /? from the command prompt.

Andriy M
  • 76,112
  • 17
  • 94
  • 154
2
echo 'C:\Program Files\Program' | sed -e 's/\\/\//g'
Blagovest Buyukliev
  • 42,498
  • 14
  • 94
  • 130