私は現在sed
fromを使用しています。呼び出すユーザーがファイルに書き込む権限がない bash スクリプトの制限を回避するために、stdin
このスクリプトを使用しています。sed
echo "..." >> outputfile.conf
これは私の目的です。書くファイルとして:
echo "<VirtualHost *:80>
...
</VirtualHost>" | sudo sed -n "w/etc/apache2/sites-available/000-default.conf"
次は何をすべきですか?追加同じファイルに?
if $enable_ssl; then
echo "<VirtualHost *:443>
...
</VirtualHost>" | sudo sed <opions-to-sed-here>
fi
ベストアンサー1
>
より高い権限または異なる権限を持つシェルの一般的な代替方法は次のとおりです。
echo "replace file content with this line" | sudo tee protectedFile >/dev/null
追加するには、以下を使用します-a
。
echo "append this line to file" | sudo tee -a protectedFile >/dev/null