The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #5 (permalink)  
Old 12-13-2006
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,798
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

Last edited by vino; 12-13-2006 at 01:22 AM..