0

How do I make umask output be 22 instead of 0022?

Server1:

user@vxs-app01> umask
22

Server2

user@vxs-app02> umask
0022
2
  • I edited the question and remove unnecessary questions (like including server 1, server 2). By the way you can change umask just typing like this; umask 22. This only for the current session. If you need permanent then you need to put this command at bootscript like rc.local or any bootscript available based on your distribution.
    – MaXi32
    Jul 30, 2020 at 17:10
  • What is the output of type umask on Server1? Jul 31, 2020 at 14:15

1 Answer 1

2

Me:
    I have 1¢ and I’d like to exchange it for $0.01.

Currency exchange cashier:
    Um, …, they’re the same thing.

You know that 22 and 0022 are the same number (if they are assumed to be in the same base), right?  If not, and I say

22 and 0022 are the same number (if they are assumed to be in the same base).

would that answer your question?  If not,

  1. You show

    user@vxs-app01$ umask
    22
    

    Do you ever get that?  Please tell us about the system where that happens.

    OK, so apparently you don’t want to tell us about the system(s) that you’re dealing with.  Then my answer is that you could be seeing any (or a combination) of what I discuss in the following paragraphs:

    • Server 1 could have umask aliased to something, or redefined as a shell function.  Type type umask to check.
    • The two systems could have different shells, or different versions of the shell.
      • zsh seems to display the umask with only one leading zero.  So that could explain 022, but not just 22.
      • csh and tcsh seem to display the umask with no leading zeros.  But csh and tcsh are radically different from bash, ksh, zsh, and other POSIX-friendly shells; if Server 1 were running csh or tcsh, you’d know.
      • Server 1 could be running a locally modified shell.
  2. If you’re just showing the 22 output on Server1 as a hypothetical example, you can get that result by typing printf '%o\n' "$(umask)", which takes the raw output from umask (with leading zeros) and displays it in the default format for an octal integer (without leading zeros).  You can then put that into an alias or a shell function.

  3. If you want the shell to remember the umask value, exactly as you typed it:

    $ umask 0022
    $ umask
    0022
    
    $ umask 22
    $ umask
    22
    
    $ umask 022
    $ umask
    022
    

    that will be harder.  The easier way would be to write a shell function to wrap umask.  If that’s what you want,

    • Try to figure out how to do it,
    • If you fail, edit your question to be clearer about what you want and what you tried, and I might devise an answer for you.


    An even harder (but more reliable) approach is to get the source of bash and modify it.

2
  • Hi , Yes, I know that both are similar but what I want to understand why on the first server appear as 22 while second server 0022 as there is another integrated script that will depend on the output value so I want to make sure how to make them have the same output while running umask command.
    – user425140
    Jul 30, 2020 at 22:57
  • Well, I believe that I’ve answered that question: you can define umask to be an alias or a shell function — although it might be tricky to get that to affect a script without modifying the script.  Or you could modify the shell. But the fact that the two servers are behaving differently is unusual, especially if they are running the same version of the same operating system, so I’m thinking that your best course of action is to figure out why they’re different, and then fix that. Jul 30, 2020 at 23:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .