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

Johnny Rosenberg gurus.knugum at gmail.com
Sat Mar 21 19:21:14 UTC 2009


2009/3/21 Johnny Rosenberg <gurus.knugum at gmail.com>

> 2009/3/21 Martin McCormick <martin at dc.cis.okstate.edu>
>
>>        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.
>
> 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?
J.R.


>
>>
>> Martin McCormick WB5AGZ  Stillwater, OK
>> Systems Engineer
>> OSU Information Technology Department Telecommunications Services Group
>>
>> --
>> ubuntu-users mailing list
>> ubuntu-users at lists.ubuntu.com
>> Modify settings or unsubscribe at:
>> https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ubuntu.com/archives/ubuntu-users/attachments/20090321/2800c884/attachment.html>


More information about the ubuntu-users mailing list