Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我怎样才能做到这一点?
sed -i 's/wiki_host/$host_name/g' /root/bin/sync
它将替换wiki_host为文本$host_name。但我想用变量的内容替换它..
wiki_host
$host_name
我试过了
sed -i 's/wiki_host/${host_name}/g' /root/bin/sync
它也不起作用。
您需要使用双引号:
$ sed -i "s/wiki_host/${host_name}/g" /root/bin/sync
您的单引号可防止 shell 变量被其内容替换。