Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > gnu.bash.bug > #15523 > unrolled thread

-e test description in the GNU Bash 5.0 man page from 7 December 2018

Started byMarco Ippolito <maroloccio@gmail.com>
First post2019-10-21 00:31 +0200
Last post2019-10-21 00:31 +0200
Articles 1 — 1 participant

Back to article view | Back to gnu.bash.bug

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  -e test description in the GNU Bash 5.0 man page from 7 December 2018 Marco Ippolito <maroloccio@gmail.com> - 2019-10-21 00:31 +0200

#15523 — -e test description in the GNU Bash 5.0 man page from 7 December 2018

FromMarco Ippolito <maroloccio@gmail.com>
Date2019-10-21 00:31 +0200
Subject-e test description in the GNU Bash 5.0 man page from 7 December 2018
Message-ID<mailman.1341.1571619692.9715.bug-bash@gnu.org>
In the GNU Bash 5.0 man page from 7 December 2018 the -e test is 
documented as such:

        -e file
               True if file exists.

When "file" is a symlink name to a non-existing target, the -e test 
fails, and this may be surprising from just reading the documentation.

By contrast, POSIX describes the same test as follows:

         -e pathname
   True if pathname resolves to an existing directory entry. False if
    pathname cannot be resolved.

POSIX provides an indication as to the potential failure of the test in 
contexts in which symlink *resolution* is performed.

It might be beneficial to reword this Linux man page.

It *may* also be beneficial to change the use of "file" in the GNU man 
page to refer to pathnames, as POSIX does, so that the distinction 
between "files" and "regular files" be more explicit.

Observe this test description on the GNU man page, for example:

        -f file
               True if file exists and is a regular file.

Here is a sample GNU script illustrating the tests alluded to above:

#! /usr/bin/env bash

# Run me on GNU/Linux

cd "$(mktemp --directory)"

touch existing_file

ln --symbolic existing_file symlink_to_existing_file
ln --symbolic non_existing_file symlink_to_non_existing_file
ln --symbolic symlink_to_existing_file symlink_to_symlink_to_existing_file
ln --symbolic symlink_to_non_existing_file symlink_to_unresolvable_symlink

{
     for pathname in \
         existing_file \
         symlink_to_existing_file \
         symlink_to_non_existing_file \
         symlink_to_symlink_to_existing_file \
symlink_to_unresolvable_symlink
do
         if [[ -e $pathname ]]; then
existence=exists
else
             existence='does not exist'
fi
         printf '[[ -e %s ]] \x1f -> \x1f %s\n' "$pathname" "$existence"
done;
} | column -t -s $'\x1f'

Outputs:

[[ -e existing_file ]]                          -> exists
[[ -e symlink_to_existing_file ]]               ->    exists
[[ -e symlink_to_non_existing_file ]]           ->    does not exist
[[ -e symlink_to_symlink_to_existing_file ]]    ->    exists
[[ -e symlink_to_unresolvable_symlink ]]        ->    does not exist


[toc] | [standalone]


Back to top | Article view | gnu.bash.bug


csiph-web