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: Thu, 16 Jul 2009 09:53:34 +0100
References: <20090715090307.GA20581@xxxxxx> <4A5DCA6C.3060804@xxxxxx> <20090715140041.GA31156@xxxxxx> <4A5E28D7.60107@xxxxxx>
Eric Blake <ebb9@xxxxxx> wrote, on 15 Jul 2009:
>
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> According to Geoff Clare on 7/15/2009 8:00 AM:
> > 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 ~.
> 
> > 
> >     case $dir in
> >     */) pathname=$dir$filename ;;
> >     *) pathname=$dir/$filename ;;
> >     esac
> 
> In this case, a direct translation to tilde-expansion won't work:
> 
> */) pathname=~$filename ;;
> 
> because it forms a tilde-prefix with characters not valid in LOGNAME
> (~$filename) and thus gives unspecified behavior.

Yes, I should have been more careful when I said "just the same".

> Using a temporary variable could be an option:
> 
> tmp=~root
> case $tmp in
> */) pathname=$tmp$filename ;;
> *) pathname=~root/$filename ;;
> esac

Yes, that's roughly what I had in mind.  (I would have used
$tmp/$filename instead of ~root/$filename.)

> but it would certainly be nicer to guarantee that ~root/$filename always
> specified the desired file, without needing an intermediate variable.
> 
> > 
> > or:
> > 
> >     pathname=$dir//$filename
> 
> This approach works to avoid the implementation-defined nature of //, but
> doesn't work if $dir is exactly //.

I think this method is considered safe when forming a pathname for
a (real) file because in that case $dir necessarily is a "normal"
directory (one that contains real files) and so could not be //
on systems where the component after // is a server name.

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

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