Email List: Xaustin-group-lX
[All Lists]

Re: [1003.1(2008)/Issue 7 0000124]: tilde expansion and doubleslash file

To: austin-group-l@xxxxxxxxxxxxx
Subject: Re: [1003.1(2008)/Issue 7 0000124]: tilde expansion and doubleslash file names
From: Geoff Clare <gwc@xxxxxxxxxxxxx>
Date: Wed, 15 Jul 2009 15:00:41 +0100
References: <20090715090307.GA20581@squonk.masqnet> <4A5DCA6C.3060804@byu.net>
Eric Blake <ebb9@byu.net> wrote, on 15 Jul 2009:
>
> > It is up to the application to deal with the double-slash issue in
> > relation to ~ in the same way it would deal with it for "$HOME".
> 
> When using $HOME, the application can do just that - via "$HOME" in
> contrast to "${HOME%/}" given the context of whether they are following
> the expansion with /.  But when using tilde expansion, the expansion is
> already performed before the user has a chance.  By arguing that the
> application must deal with it, you are claiming that a conformant
> application cannot safely use tilde expansion as a substitute for $HOME.

I hadn't considered the use of "${HOME%/}".  Historically, the
way to handle the double-slash issue when joining a directory
and a filename was either:

    case $dir in
    */) pathname=$dir$filename ;;
    *) pathname=$dir/$filename ;;
    esac

or:

    pathname=$dir//$filename

These techniques predate the standardisation of ${var%pattern} by
POSIX.2.

Both techniques can be used with ~ just the same as with "$HOME",
but you have a point that the more modern "${dir%/}" technique
can be used with "$HOME" but not with ~.

-- 
Geoff Clare <g.clare@opengroup.org>
The Open Group, Thames Tower, Station Road, Reading, RG1 1LX, England

<Prev in Thread] Current Thread [Next in Thread>