dirname and basename errors

From: Remi Villatel (maxilys_at_SPAMCOP.tele2.fr)
Date: 04/01/04

  • Next message: Chris F.A. Johnson: "Re: 20 basic Linux newbie commands to identify the system"
    Date: Thu, 01 Apr 2004 02:10:00 +0200
    
    

    Hi everybody,

    I encountered a strange behavior of dirname and basename:

    % dirname aaa/bbb/ccc/
    aaa/bbb

    % basename aaa/bbb/ccc/
    ccc

    Both are wrong answers! dirname should return "aaa/bbb/ccc/" unchanged and
    basename shoud return an empty string IMHO.

    How can I obtain correct answers from them with a pathname without a real
    filename as in my example?

    I introduced a test to check if the last char of the pathname is "/" but
    isn't there anything more simple?

    See ya,

    ==================
    Remi Villatel
    maxilys_@_tele2.fr
    ==================


  • Next message: Chris F.A. Johnson: "Re: 20 basic Linux newbie commands to identify the system"

    Relevant Pages

    • Re: dirname and basename errors
      ... Remi Villatel wrote: ... | I encountered a strange behavior of dirname and basename: ...
      (comp.os.linux.misc)
    • Re: [opensuse] bash pipe
      ... On Tuesday 30 September 2008 00:19, Brian K. White wrote: ... than the unnecessary process fork of running basename. ... I'd composed a message with this (and the dirname counterpart, ... The first gives you an empty string if you're in "/", ...
      (SuSE)
    • Re: Command-line equivalent of "Create archive of..."
      ... Use basename and dirname to get just the filename and path respectively from a combined path/filename. ... The shell command that you need to execute is: ...
      (uk.comp.sys.mac)
    • Re: dirname and basename errors
      ... > basename shoud return an empty string IMHO. ... in a slash should be interpreted as if it had a dot after it). ... write your own functions to replace basename and dirname. ...
      (comp.os.linux.misc)
    • Re: Getting path components
      ... you can use dirname() and basename() in combination. ... also realpath() if you need it. ... basename from OpenSSH:- ...
      (comp.lang.c)