Bikr
Bikr

Reputation: 11

My sed from a bash script terminates when ran with "unterminated address regex"

Having some issues with a bash script I'm assembling.

$2 is a string similar to "line_old" that's supplied during launch. The sed dies with

sed: -e expression #1, char 15: unterminated address regex

Here is my code snippet:

redisconfig ()
{
    CMD="ssh -q -t -i $HOME/.ssh/amazon-key.pem [email protected]"

    line_old="ENV['REDIS_URL'] = 'redis://redis:[email protected]:6379'"

    line_new="ENV['REDIS_URL'] = 'redis://redis:X9gKQasdg2yY4@$2:6379'"

    updateconfig="$($CMD sed "/$line_old/c\$line_new/" /home/ubuntu/config/testing.rb)"

    results="$($CMD grep 'REDIS_URL' /home/ubuntu/config/testing.rb)"

    echo $updateconfig

    echo $results    
}

Any idea what could be going on with me sed? Thanks so much!

Upvotes: 1

Views: 4249

Answers (1)

Zulu
Zulu

Reputation: 9265


I think the trouble is // in $line_old and $line_new.
It causes problem with sed delimiters

I wish I had your file for work on it, but I can give you the way :
You can use sed with different delimiters, for example :

$ echo 'foo' | sed s#foo#bar#
bar

More here.

Upvotes: 1

Related Questions