because of the latest answer to your post, i have just seen your post and answering now.
In linux I can enquire umask using /usr/bin/umask. In my case, env does not report anything about umask. Umask is usually set when a shell like bash starts. For bash that happens probably via ~/.bashrc, /etc/bashrc, /etc/profile. But for other shells, like csh it could be in other files. So, each shell has its own configuration setup and somewhere in there should be a umask. Of course you could insert one yourself umask 022 at the end of your ~/.bashrc and that will overwrite any previous umask settings.
When you run system("env ...") you will get the ENV of some shell that Perl spawns via system(). (In my system that's sh). When you run system("xterm") you will create an xterm which will then launch a shell. Now which shell will that be? Perhaps $XTERM_SHELL can give you a hint. The new shell will inherit environment from parent and also read configuration from rc files. Sometimes Perl's system() will not launch a new shell just to run your command but instead it will run the command directly if it's possible. So, if it launches a shell, that could be sh. (In my system, system("xterm") causes Perl to run a sh -c xterm which in turn spawns a bash shell.) It will then read some configuration files, and then run xterm which launches yet another shell which inherits env from parent shell and also reads some configuration from its own rc files. If your current shell is bash but xterm launches sh, then it's possible to have different umasks.
Regarding ENV inheritance, the following says it all, it creates a shell within a shell which had its umask chamged. The new shell inherit's parent shell's umask:
% umask
0002
% umask 0
% umask
0000
% bash
%% umask
0000
%% exit
Bottomline: there are a lot of shells being spawned, one inside the other in what you are doing. Shells inherit their environment (and also umask) from parent shells. They also configure using rc files (like ~/.bashrc). If you can find which shell your xterm runs then you can edit its configuration and alter its umask. Alternatively, force xterm to launch the shell you want which reads from the rc file you want:system("echo 'umask 03' > mybashrc; xterm -e '/bin/bash --rcfile mybashrc'"); . For me, this creates an xterm running bash with umask 0003. |