GNU bug report logs -
#8749
mkdir: feature request --reference
Previous Next
Full log
Message #41 received at 8749 <at> debbugs.gnu.org (full text, mbox):
Shaun Jackman wrote:
> I was using exactly that shell function that you described, but it
> doesn't work for
> mkdir -p foo/bar
Since we are talking about shell aliases and functions here is a
simple shell snippet that can create the directories with the modes
explicitly.
#!/bin/sh
mkdir_px() {
case $1 in */*) mkdir_px $(dirname "$1") ;; esac
test -d "$1" || mkdir -m $(stat -c %a .) "$1"
}
mkdir_px "$@"
exit $?
It is a little bit long but not unduly so.
> I've noticed one issue, which I feel is a bug in mkdir. When using mkdir
> -pm, the specified mode is applied only to the final directory and not
> the parent directories:
>
> $ mkdir -pm 775 foo/bar
> $ ls -ld foo foo/bar
> drwxr-xr-x 3 sjackman assembly 4096 May 30 10:27 foo
> drwxrwxr-x 2 sjackman assembly 4096 May 30 10:27 foo/bar
>
> I would expect both foo and foo/bar to have mode 775.
That is the original traditional behavior of 'mkdir -p'. As Paul
pointed out in his follow-up that behavior has been in use and is now
standardized by POSIX lest some new implementation decides to do
something different from the previously implemented behavior. It is
unfortunate that it was originally implemented that way but having
done so and gotten into common use it is too late to change it now.
That is why POSIX exists is to prevent the proliferation of different
features on every system when corner case behavior like this is
found. You can pretty much guarentee that someone is counting on that
behavior if for no other reason than just by accident.
Bob
This bug report was last modified 14 years and 78 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.