sed - shell script, how to escape variables? -
i writing shell script input value , want use value other commands. problem want escape value.
for example, if input http://example.com
in following script
echo "input value my_value" read my_value echo $my_value
it result in http://example.com
but result wish http\:\/\/example\.com
how achieve this?
command i'm trying run is
sed -i s/url/$my_value/g somefile.html
without escape becomes sed -i s/url/http://example.com/g somefile.html
syntax error..
you can use other characters split s
arguments. ,
sed -i 's,url,http://example.com,g'
. if want can use sed replace /
in argument, before executing
url=$(echo "http://example.com"|sed 's,/,\\/,g') sed -i 's/url/'"$url"'/g' input
Comments
Post a Comment