umask is an attribute of a process, not a file, that is part of the UNIX architecture and has nothing to do with Bash or any other shell program.
The real problem is that the programs you use do not allow you to change permissions when creating. In C, for example, mkdir has a second parameter, mode.
You do not need to write C, but Python and Perl allow you to use low-level interfaces. Permissions will be changed by the umask process, so if you do not want any changes, set unmask to zero.
/home/user1> umask 000 /home/user1> python -c 'import os;os.mkdir("mydir",0701)' /home/user1> ls -ld mydir drwx-----x 2 user1 QAPLADV 4096 Sep 16 10:28 mydir /home/user1> python -c 'import os;os.open("myfile",os.O_CREAT,0604)' /home/user1> ls -l myfile -rw----r-- 1 user1 QAPLADV 0 Sep 16 10:32 myfile
Do not forget that at the moment umask is still 000, you can return it back to its previous value if you are doing any other work in the same process.
Here is the version of Perl if you prefer:
perl -e "mkdir mydir,0701" perl -MFcntl -e 'sysopen(my $h,"myfile",O_EXCL|O_CREAT,0604)'
Of course, if you have a large number of files, and you are likely to run this often, then it will be much better for you to write a Perl or Python program to complete the task. Perl or python is called for each file. a little inefficient.
source share