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.
Asked
Active
Viewed 1.4k times
10
-
... 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 Answers
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
-
I am getting a "sed: -e expression #1, char 8: unterminated `s' command" error – remo May 31 '11 at 15:31
-
-
1Alternatively, to avoid the picket fence: `echo 'C:\Program Files\Program' | sed -e 's_\\_/_g'` – vmrob Oct 23 '14 at 18:01