Umask to generate files with rwx permissions for all

i need my script1.sh to generate /tmp/temp.txt with full permissions i.e

-rwxrwxrwx   1 user1 users    23 Dec 16 10:52 /tmp/temp.txt
more script1.sh
umask 666
echo "hello">/tmp/temp.txt

But the script1.sh generates temp.txt with different permissions as shown below.

-rwxr-xr-x   1 user1 users  23 Dec 16 10:52 /tmp/temp.txt

I tried umask 600, 000 but they also did not help.

The reason i wish to give complete permissions is; so that other user executing script1.sh should not get the /tmp/temp.txt: Permission denied error.

777 is not the magic sledgehammer to fix all permission problems. Stop that.

umask cannot grant execute permissions, not ever. They may not need execute permissions though, even if running it as a script.

What permissions does user2 actually want? Are they reading, writing, or executing the file?

umask 007 will give rw- permissions for user and group and nothing for anyone else, that should work for data files.

This has nothing to do with shell scripting, but understanding how are set and works unix permissions...
Thread moved to more adequate forum : Beginners Q and A

1 Like

Run my script with multiple users and it will fail for all users except the first.

You do realize that umask only has an effect when creating a new file, don't you? To change the mode of an existing file, use chmod mode file... ; not umask .

But, we know that the data you're showing us above was for a case where /tmp/temp.txt already existed and we know that your latest update to that file was not performed by the echo command you showed us. If the file had not already existed and you used the above commands, the output from ls -l would have been:

----------   1 user1 users  6 Dec 16 10:52 /tmp/temp.txt

not:

-rwxr-xr-x   1 user1 users  23 Dec 16 10:52 /tmp/temp.txt
1 Like

Just to make it explicitly clear (although implicitly alluded above): umask defines a MASK to be inverted & ANDed with the permissions supplied: the bits set in it will be turned OFF when a file is freshly created. man umask :

2 Likes

Could you answer any of my questions about what permissions are needed please?