#3567 anomaly in [file tail] under ~ expansion

obsolete: 8.5a5
open
Don Porter
3
2009-10-01
2006-11-06
Colin McCormack
No

[file tail ~fred/wilma] will return "wilma", but [file
tail ~fred] will error, if there is no ~fred (that is,
if the user fred does not exist.)

It seems that when the terminal element of a file
path/name is ~, it is expanded.

I think that there's no good reason for [file tail] to
have an existential interpretation, but that
normalization of the path with a ~-element forces the
existence to be tested implicitly and unintentionally.

Discussion

  • Don Porter
    Don Porter
    2006-11-06

    Logged In: YES
    user_id=80530

    Did some testing in old
    Tcl releases and this behavior
    is not new. Same happens
    in both 8.3.5 and 7.6p2.

    If this were to be "fixed",
    what would the correct behavior be?

     
  • Don Porter
    Don Porter
    2006-11-06

    • priority: 5 --> 3
     
  • Logged In: YES
    user_id=19214

    I believe the correct behaviour would be to return "~fred"
    to [file tail ~fred] when the user fred doesn't exist.

    I note another anomaly: [file tail ~colin/wilma] returns
    "wilma" and [file tail ~colin] returns "colin" (being the
    tail of the expanded path.)

    It seems (from experiment, not looking at the source) that
    the expansion is intentionally performed iff the result of
    [file tail] yields a ~-form. This is unexpected behavior,
    and inconsistent with such things as [file tail ~fred/..]
    and so, I believe, it should be removed as surprising and
    not particularly useful.

    Most people, I imagine, use [file tail] as a shorthand for
    [lindex [file split] end]. If they wanted expansion, they
    could use [file normalize].

     
  • Don Porter
    Don Porter
    2006-11-09

    Logged In: YES
    user_id=80530

    is there any connection
    between this and 858937?

     
  • Don Porter
    Don Porter
    2009-10-01

    • assigned_to: vincentdarley --> dgp