Sed and Bash; unterminated 's' command

Liberty Young plug-discuss@lists.plug.phoenix.az.us
19 Mar 2003 08:16:01 -0700


On Wed, 2003-03-19 at 08:16, Mike Starke wrote:
> On Wed, Mar 19, 2003 at 08:01:20AM -0700, Liberty Young wrote:
> /_
> /_So, the following command works from the command prompt:
> /_
> /_
> /_ sed -ne "s|^foobar[[:blank:]]|foo bar|p;p" processed_file
> /_
> /_Basically, replace foobar followed by a whitespace with foo bar
> /_
> /_Now, i'm trying to execute the same command in a bash script:
> /_
> /_#!/bin/bash
> /_
> /_sedrules="s|^foobar[[:blank:]]|foo bar|p;p"
> /_file=processed_file
> /_
> /_sed -ne $sedrules $file
> /_
> /_#done
> /_
> /_which errors out with: sed -e expression #1, char 27: unterminated `s'
> /_command
> /_
> /_I've googled and found out it has to do with bash and the quotes. Doing
> /_the same command at the command prompt, but without placing quotes
> /_around the expression, gives me the same error. But
> /_sedrules="'s/foobar//p'" doesn't work either. It gives me a sed error of
> /_unknown command
> /_
> /_Anybody come across this before and have any suggestions? Google pointed
> /_me in the right direction, but with no solutions. 
> /_
> 
> Far from my specialty, but maybe you need to escape the | (pipe) character?


I used | for readability. It does the same error if i use the typical /
or any other character, like #