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


Groups > gnu.bash.bug > #15523

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

From Marco Ippolito <maroloccio@gmail.com>
Newsgroups gnu.bash.bug
Subject -e test description in the GNU Bash 5.0 man page from 7 December 2018
Date 2019-10-21 00:31 +0200
Message-ID <mailman.1341.1571619692.9715.bug-bash@gnu.org> (permalink)
References <6f5fd3b2-2e3b-4730-b2d8-50b89e9e3085@gmail.com>

Show all headers | View raw


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


Back to gnu.bash.bug | Previous | Next | Find similar | Unroll thread


Thread

-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

csiph-web