2019-06-05 18:00:21 +0700, Robert Elz: [...] > mkdir a && cd a || exit 3 > case "$(echo .*)" in > '. ..') exit 2;; > . | ..) exit 1;; > '' | '.*') exit 0;; > *) echo "Strange glob!" >&2; exit 3;; > esac > ) > case "$?" in > 3) echo "Sorry... No idea"; exit 1;; > 2) echo ". and .. are included";; > 1) echo "One of . or .. is included!";; > 0) echo ". and .. are excluded";; > esac [...]
As already discussed, like the [ .[.] = .. ] approach, that's not foolproof because on a given system, there can be directories where "." and ".." are returned by readdir() and some where they aren't. So, if you don't get any "." and "..", that can be because you're on a file system that doesn't have "." nor ".." and the shell uses a readdir() that doesn't synthesize them but the shell doesn't skip them, or that can be because the shell skips them. IOW, if "." and ".." are not there, that only tells us they are not included in a newly created directory in the current directory, but chmod -R a-x /elsewhere/.* may still do a recursive chmod on / (/elsewhere/.. assuming /elsewhere is not a symlink). To be certain that the shell skips them, you'd need first to find a directory where they are included. Like ! LC_ALL=C ls -qa / | grep -xqF ..; r1=$? ! ([ /.[.] = /.. ]) 2> /dev/null; r2=$? case $r1$r2 in (00) echo "I don't know";; (01) echo "It synthesizes them";; (10) echo "It skips them";; (11) echo "It either preserves or synthesizes them";; esac (assuming the shell uses the same method to read the content of directories as ls does). -- Stephane
