Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

How can I interactively execute a command in Linux (zsh, if it matters) with a different umask from the default, for one command only? Perhaps a combination of commands combined in a single line? The new umask should apply only to that command and return to its default value for the next command entered.

Ideally the command would be agnostic to the default umask in force before its entered (in other words, the default umask doesn't have to specified).

share|improve this question
add comment

2 Answers 2

up vote 4 down vote accepted

Start a subshell:

(umask 22 && cmd)

Then the new umask will only alter that subshell.

Note that zsh executes the last command of the subshell in the subshell process instead of forking another one, which means that if that command is external, you're not even wasting a process, it's just that the fork is done earlier (so the umask is done in the child process that will later execute your command).

share|improve this answer
add comment

You could wrap it in a shell script. umask inherits to all child processes.

cmd.sh:

umask 0022
cmd
share|improve this answer
    
Or, if you want to do it in one command line, you can invoke a shell like this, "$ (umask 0022; cmd)" –  Rob Bos Feb 23 '13 at 19:11
    
I confused $ ( with $( in your comment, now I understand: ( umask 0022; cmd ). –  donothingsuccessfully Feb 23 '13 at 20:21
    
whoops, well, at least someone clarified that ^^ –  Rob Bos Feb 23 '13 at 23:05
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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