shell script string caret trick

sed wants to replace a string, but the replacement result contains special characters, causing sed expression errors, such as 

 

sed -r "s/^url.*$/url=$(pwd)/" rt.conf

 The expression $(pwd) contains a slash, which conflicts with the delimiter in sed, so it must be processed first

 

 

x=file://$(pwd)
#Note the following replacement, x is followed by two //, if only one is connected, only the first one will be replaced.
DIR="${x//\//\/}"
sed -f "s/^url.*$/url=$x/" rt.conf

 

 

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326573544&siteId=291194637