I am trying to append some config to another file like this

sudo cat config/add-this.yml >> ~/docker-compose.yml

via shell script. But trying this gives me a Permission denied error.

How can I simply append some content to another file?


The problem is that the shell performs redirections before the command is executed.

In this case. unless the permissions of the file into which data is to be added allow appending, a permission denied error results.

You can circumvent this by doing:

sudo sh -c 'cat config/add-this.yml >> ~/docker-compose.yml'
  • So it would also work if I would set chmod 777 docker-compose.yml, right? – user3142695 Feb 10 '17 at 22:32
  • Yes, though opening permissions is often the wrong approach. Some configuration files must have r/w permissions and only by the owner for a daemon to accept the file for processing. – JRFerguson Feb 10 '17 at 22:54
  • What does the -c-flag do? – user3142695 Feb 10 '17 at 22:59
  • -c reads and executes commands from the first non-option argument command_string, and then exits. See here . – JRFerguson Feb 10 '17 at 23:23

Not the answer you're looking for? Browse other questions tagged or ask your own question.