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

Re: [1003.1(2008)/Issue 7 0000124]: tilde expansion and double slashfile

To: Geoff Clare <gwc@xxxxxxxxxxxxx>
Subject: Re: [1003.1(2008)/Issue 7 0000124]: tilde expansion and double slashfile names
From: Eric Blake <ebb9@xxxxxxx>
Date: Wed, 15 Jul 2009 13:07:03 -0600
Cc: austin-group-l@xxxxxxxxxxxxx
References: <20090715090307.GA20581@squonk.masqnet> <4A5DCA6C.3060804@byu.net> <20090715140041.GA31156@squonk.masqnet>
-----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.

Using a temporary variable could be an option:

tmp=~root
case $tmp in
*/) pathname=$tmp$filename ;;
*) pathname=~root/$filename ;;
esac

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 //.

- --
Don't work too hard, make some time for fun as well!

Eric Blake             ebb9@byu.net
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkpeKNcACgkQ84KuGfSFAYDvRQCaA7cre2U3Sh+ZSNa2IjzmLA37
XNwAoKticzgPzrFcKDC9K6UWXRqaC/nf
=Z2hT
-----END PGP SIGNATURE-----

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