I want to replace backslash(\
) with forward slash(/
) in a variable in bash.
I tried it like this, but it doesn't work:
home_mf = ${home//(\)//(/)}
For example, I would like
\a\b\c -> /a/b/c
bashbash-scripting
I want to replace backslash(\
) with forward slash(/
) in a variable in bash.
I tried it like this, but it doesn't work:
home_mf = ${home//(\)//(/)}
For example, I would like
\a\b\c -> /a/b/c
Best Answer
The correct substitution is
This breaks up as follows:
//
replace every\\
backslash/
with/
slashDemonstration:
An alternative that may be easier to read would be to quote the pattern and the replacement: