Quote:
|
Originally Posted by sakthi.abdullah
abc=`echo "a/b/d" | sed 's#/#\\/#g'`
|
Turn the backticks into $(...). See this.
Code:
[~]$ abc=`echo "a/b/d" | sed 's#/#\\/#g'`
[~]$ echo $abc
a/b/d
[~]$ abc=$(echo "a/b/d" | sed 's#/#\\/#g')
[~]$ echo $abc
a\/b\/d
[~]$
Hmm.. I am a little surprised with the difference in behaviour of `...` and $(...)
Edit
Ah ! Here's how it goes with the backticks.
Code:
[/tmp]$ abc=`echo "a/b/d" | sed 's#/#\\\\/#g'`
[/tmp]$ echo $abc
a\/b\/d
And here's why. From man sh
Code:
When the old-style backquote form of substitution is used, backslash
retains its literal meaning except when followed by $, ?, or \. The
first backquote not preceded by a backslash terminates the command sub-
stitution. When using the $(command) form, all characters between the
parentheses make up the command; none are treated specially.
/Edit