help-bash
[Top][All Lists]
Advanced

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

Re: Manual descriptions for -a file and -e file


From: Andreas Kusalananda Kähäri
Subject: Re: Manual descriptions for -a file and -e file
Date: Mon, 27 Mar 2023 09:10:00 +0200

On Mon, Mar 27, 2023 at 06:51:06AM +0000, uzibalqa wrote:
> 
> 
> 
> ------- Original Message -------
> On Monday, March 27th, 2023 at 6:43 PM, Andreas Kusalananda Kähäri 
> <andreas.kahari@abc.se> wrote:
> 
> 
> > On Mon, Mar 27, 2023 at 06:05:19AM +0000, uzibalqa wrote:
> > 
> > > In the bash manual under "6.4 Bash Conditional Expressions" I see the 
> > > following.
> > > 
> > > -a file
> > > True if file exists.
> > > 
> > > -e file
> > > True if file exists.
> > > 
> > > Could there be some brief comment about their difference?
> > 
> > 
> > They are identical. This is the C code that detects when -a and -e is
> > used:
> 
> 
> It would help if the manual for "-a FILE" stated that it is equivalent to "-e 
> FILE".

Why? Their description is the same, which implies they are identical,
which is also true for -L and -h.

> > 
> > switch (op[1])
> > {
> > case 'a': /* file exists in the file system? */
> > case 'e':
> > return (sh_stat (arg, &stat_buf) == 0);
> > 
> > That's from here:
> > https://git.savannah.gnu.org/cgit/bash.git/tree/test.c#n526
> > 
> > These two lines of code have been unchanged since 1996 (bash 1.14).
> > There is no further clue in any commit messages, but I'm assuming this
> > is to align with the original ksh shell, which also has these two test
> > operators with the same semantics. Whe the ksh shell used both -a and
> > -e, I don't know.

After reading the POSIX rationale, it seems ksh originally used -a, but
added -e when the POSIX standard opted to use -e as to not introduce too
much confusion between -a (the file existence test) and -a (the AND
operator, since deprecated).  Bash then added support for both as a way
of being ksh compatible.


> > 
> > The original Bourse shell did not have -e nor -a for testing whether
> > a file exist. You had to some other test that not only tested for
> > existence but also for e.g. readability, writability, file type or
> > something else.
> > 
> > --
> > Andreas (Kusalananda) Kähäri
> > SciLifeLab, NBIS, ICM
> > Uppsala University, Sweden
> > 
> > .

-- 
Andreas (Kusalananda) Kähäri
SciLifeLab, NBIS, ICM
Uppsala University, Sweden

.



reply via email to

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