sed within `` in Bourn Shell isn't Working.

Martin McCormick martin at dc.cis.okstate.edu
Sat Mar 21 22:16:26 UTC 2009


Johnny Rosenberg writes:
> > I don't know, I got the same error, but there is an alternate method of
> > doing the same thing, and it worked for me:
> > #! /bin/sh
> >
> > uid=$(echo "ABC\DEF" | sed 's/\\//g')
> > echo ${uid}
> > J.R.
> >
> >
> Or, if replacing \ by \\, this code:
> #! /bin/sh
> 
> uid=$(echo "ABC\DEF" | sed 's/\\/\\\\\\/g')
> echo ${uid}
> 
> Can someone explain to me why I need 6 ?\?, by the way?

	It worked exactly the same way for me. Thank you. I
think what we gain here is that we are not running a subshell.
As to why you need 6 \ characters in order to get 2 to print
when one would expect to have to only use 4, I am not totally
sure either, but just for laughs, I tried 8 \'s and still only
got 2 out. Ten of them did give me 3 out with 4 mystery
sacrificial backslashes to the shell god.:-) It is as if some
sort of recursion is going on but I don't really understand why.

	Thanks for solving my immediate problem and maybe
someone knows why we must sacrifice so many extra \'s. 

Martin McCormick WB5AGZ  Stillwater, OK 
Systems Engineer
OSU Information Technology Department Telecommunications Services Group




More information about the ubuntu-users mailing list