help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-bash] How to safely work on files/dirs with .


From: Bob Proulx
Subject: Re: [Help-bash] How to safely work on files/dirs with .
Date: Sat, 19 Mar 2016 11:31:13 -0600
User-agent: Mutt/1.5.24 (2015-08-30)

Stephane Chazelas wrote:
> chmod [...] +r [...]

I saw this and wanted to comment.  I tend to avoid bare permissions.
Those that start with a + or - but don't specify one of the explicit
[ugoa] letters.  Because then it depends upon the setting of umask.

  mkdir /tmp/trial
  cd /tmp/trial
  touch foo

  chmod a-w foo
  ls -ldog foo
    -r--r--r-- 1 0 Mar 19 11:22 foo
  umask 02
  chmod +w foo
  ls -ldog foo
    -rw-rw-r-- 1 0 Mar 19 11:22 foo

  umask 022
  chmod a-w foo
  chmod +w foo
  ls -ldog foo
    -rw-r--r-- 1 0 Mar 19 11:22 foo

  umask 0222
  chmod a-w foo
  chmod +w foo
  ls -ldog foo
    -r--r--r-- 1 0 Mar 19 11:22 foo

  umask 027
  chmod a-rw foo
  chmod +r foo
  ls -ldog foo
    -r--r----- 1 0 Mar 19 11:22 foo

Because the result depends upon umask, which is an invisible
attribute, it makes me nervous that the result will be what is
intended.  And by intended I mean that one person with a umask of 02
intends it to be one way and another person with a umask of 022
intends it to be a different way.  Both can argue about which is what
they want to have happen.

Therefore I prefer to program my scripts with an explicit target to
the action using one of [ugoa].  There is no doubt about the intention
when doing these following for example.

  chmod o-w foo
  chmod a-w foo
  chmod a+r foo
  chmod a+rw,o-w foo
  ...and so forth...

And then the setting of umask is not involved in the result.
Especially because some people have umask 027 set causing a result
other than what I want to have happen.

Bob



reply via email to

[Prev in Thread] Current Thread [Next in Thread]