--pWyiEgJYm5f9v55/
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Sat, Jul 19, 2008 at 04:27:09AM +0900, C.E. Thornton wrote:
> Looking at the code I see that, However:
>=20
>  When the path ~name it by definition IS NOT A VALID  pathname.
>=20
>  FOR EXAMPLE:   if your home dir is "/home"
>=20
>  In your home directory make the following directories
>   "/home/test" and "/home/~test"
>=20
>  Check these results:
>=20
>   cd test     =3D=3D> /home/test
>   cd ~test   =3D=3D> /home/~test      # Note this interpreted as "/home/~=
test"
>                                                   # NOT /home/test !
>   cd ~/test  =3D=3D> /home/test
>=20
>   So as you can see -- It appears that Ruby mishandles path expansion!
>=20

The logic, as implemented by the Bourne shell, is that when a tilde is=20
encountered as an element of a path, it's expanded to the home directory of=
=20
the user. If the tilde is followed immediately by the name of a user, it's=
=20
expanded to that user's home directory. If the tilde is followed by somethi=
ng=20
other than a path separator that is not the name of a user, it isn't expand=
ed=20
at all. In any case, the tilde can be escaped with a backslash. This is a=
=20
macro expansion performed regardless of whether a directory actually named=
=20
~whatever exists, as shown below.

It's not a Linux/Unix thing per se, but a behavior of the Bourne shell that=
's=20
been adopted in other contexts.

Demonstration in DASH, a POSIX-compliant Bourne shell:

$ whoami
mboeh
$ echo $HOME
/home/mboeh
$ echo ~
/home/mboeh
$ echo ~mboeh
/home/mboeh
$ echo ~root
/root
$ echo ~root/mysterious_directory
/root/mysterious_directory
$ echo \~mboeh
~mboeh
$ mkdir \~root
$ echo ~root
/root
$ echo ~nosuchuser
~nosuchuser

That said, it appears File#expand_path is inconsistent with the Bourne shel=
l=20
in that "~nosuchuser" raises an exception rather than just leaving the tild=
e=20
unexpanded.

--=20
Matthew Boeh

--pWyiEgJYm5f9v55/
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: Digital signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)

iD8DBQFIgRcAfi+i1R7d/ZwRAloOAKCRnHcVNTsqZDoQKCMCsrOtHjfRywCfeCL5
tf5VEyT8gro702nNcJltivs=
=v1QG
-----END PGP SIGNATURE-----

--pWyiEgJYm5f9v55/--

On Sat, Jul 19, 2008 at 04:27:09AM +0900, C.E. Thornton wrote:
> Looking at the code I see that, However:
>=20
>  When the path ~name it by definition IS NOT A VALID  pathname.
>=20
>  FOR EXAMPLE:   if your home dir is "/home"
>=20
>  In your home directory make the following directories
>   "/home/test" and "/home/~test"
>=20
>  Check these results:
>=20
>   cd test     =3D=3D> /home/test
>   cd ~test   =3D=3D> /home/~test      # Note this interpreted as "/home/~=
test"
>                                                   # NOT /home/test !
>   cd ~/test  =3D=3D> /home/test
>=20
>   So as you can see -- It appears that Ruby mishandles path expansion!
>=20

The logic, as implemented by the Bourne shell, is that when a tilde is=20
encountered as an element of a path, it's expanded to the home directory of=
=20
the user. If the tilde is followed immediately by the name of a user, it's=
=20
expanded to that user's home directory. If the tilde is followed by somethi=
ng=20
other than a path separator that is not the name of a user, it isn't expand=
ed=20
at all. In any case, the tilde can be escaped with a backslash. This is a=
=20
macro expansion performed regardless of whether a directory actually named=
=20
~whatever exists, as shown below.

It's not a Linux/Unix thing per se, but a behavior of the Bourne shell that=
's=20
been adopted in other contexts.

Demonstration in DASH, a POSIX-compliant Bourne shell:

$ whoami
mboeh
$ echo $HOME
/home/mboeh
$ echo ~
/home/mboeh
$ echo ~mboeh
/home/mboeh
$ echo ~root
/root
$ echo ~root/mysterious_directory
/root/mysterious_directory
$ echo \~mboeh
~mboeh
$ mkdir \~root
$ echo ~root
/root
$ echo ~nosuchuser
~nosuchuser

That said, it appears File#expand_path is inconsistent with the Bourne shel=
l=20
in that "~nosuchuser" raises an exception rather than just leaving the tild=
e=20
unexpanded.

--=20
Matthew Boeh
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)

iD8DBQFIgRcAfi+i1R7d/ZwRAloOAKCRnHcVNTsqZDoQKCMCsrOtHjfRywCfeCL5
tf5VEyT8gro702nNcJltivs=
=v1QG
-----END PGP SIGNATURE-----