2

I've made a Makefile to simplify my life, and this Makefile calls a script in a bin file I've created. After running my command make something, I got following error :

/bin/sh: 1: .docker/bin/echo-title: Permission denied 

After searching a bit and thanks to this answer, I gave execute permission to the user who created the file (aka: me) with chmod command. My question is : Since I'm the owner of the file, shouldn't I have execute permission right away? And if not... why?

This is for a personal project, but at work we're also using Makefiles and bin scripts, exactly this way (I actually copied and pasted the base content of the files) and I don't have to run a chmod command to run the scripts. Why is that so?

(Running other commands in the Makefile that don't involve bin script work well.)

1 Answer 1

2

It's not recommended to give all newly created files execute permissions as most files don't need to be executed.

umask(2) is used to determine what the default file permissions will be. If you just run umask with no options it will print the current value for your user. This is the value that will be subtracted from the permissions a particular application uses when creating a file, typically 666 (rw-rw-rw-) permissions for files or 777 (rwxrwxrwx) permissions for directories.

So if your umask value is 002 (pretty common) then when you create a new file it will get permissions of 664 (rw-rw-r--).

You can modify the default umask value by running umask new_value ie: umask 044, although since you can only subtract from 666 for files you won't be able to use it to default execute. Also to make it persistent you would need to add that to your rc or profile config file.

Related:

Why doesn't umask change execute permissions on files?
How umask works
how to give execute permission by umask
Why does umask 077 not allow the user to execute files/directories?

3
  • Thanks for these explanations (and for the resources)! I've just run the command and indeed, my umask value is 002. I'm guessing then that at work it's not the same. I'll run umask there to confirm that. Commented Dec 20, 2019 at 17:39
  • 3
    Not quite right. The umask masks whatever permissions the process supplies when creating the file. It is not required that applications use 0666 or 0777. That is merely common. Commented Dec 20, 2019 at 17:50
  • Typically, the project (editable) version of the script would have an extension like .bash or .sh. Your make install for echo-title would copy it into some bin directory, rename it without the extension, and chmod +x it. You can create a make rule to do those things for all your scripts, as part of an install or release target.. Commented Nov 25, 2020 at 12:42

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.