shaveax
shaveax

Reputation: 478

how to use sed command with several slashes in bash

I am trying to use SED command with a variable that contains several / and i got the following error :

sed: -e expression 1, char 16: unknown option to s

this is my code and this is inside a script:

thispath=$(readlink -f $0)
sudo sed -i '13s/^/'"$thispath"'/g' /etc/rc.local

and the variable contains for example: /home/user/script.sh i do not know very well the use of sed can somebody help me

Upvotes: 0

Views: 150

Answers (1)

sureshvv
sureshvv

Reputation: 4412

The s command is sed allows you to use any character to delimit the regex and replacement parts. "/" is often a poor choice given how often you come across it in UNIX paths:

Try:

sudo sed -i '13s:^:'"$thispath"':g' /etc/rc.local

It is dangerous to do this directly on rc.local. So make a copy first.

Upvotes: 2

Related Questions