bug-bash
[Top][All Lists]
Advanced

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

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


From: Marco Ippolito
Subject: -e test description in the GNU Bash 5.0 man page from 7 December 2018
Date: Mon, 21 Oct 2019 00:31:41 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.9.0

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





reply via email to

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