sed within `` in Bourn Shell isn't Working.
Thomas Kaiser
ubuntu at kaiser-linux.li
Sat Mar 21 18:35:17 UTC 2009
Martin McCormick wrote:
> I am doing something wrong but not sure what. This works
> from the command line:
>
> echo "ABC\DEF" | sed 's/\\//g'
>
> What you get is ABCDEF without the \ character.
>
> In a script, however, I am trying to replace the \ with
> \\ and assign the output to a variable but the `` construct
> seems to throw the whole thing off.
>
> #! /bin/sh
> uid=`echo "ABC\\DEF" | sed 's/\\/\\\\/g'`
> echo $UID
>
> I get an error like:
>
> sed: -e expression #1, char 6: unterminated `s' command
>
>
> I have actually tried this same script on a FreeBSD
> system. That version of sed echos back the whole command and
> also complains about the unterminated s command. The second ' is
> right next to the ` so I know it's there but the `statements`
> must be confusing things.
>
> What am I missing here?
>
> Thanks.
Try this:
uid=`echo "ABC\DEF" | sed 's/\\\/\\\\\\\/g'`; echo $uid
Thomas
More information about the ubuntu-users
mailing list