日々精進

新しく学んだことを書き留めていきます

sudo echo "append" >> /etc/environmentのようにファイルに文字列を追加しようとするとPermission deniedになる

この場合、以下のようにすると文字列を追加できる。

sudo bash -c "echo 'test' >> /etc/file"

sudo bash -cをpipeの後のコマンドもsudo権限で実行されるのか。なるほど。
参考:linux - Permission denied when trying to append a file to a root owned file with sudo - Stack Overflow