X-Spam-Check-By: sourceware.org From: ericblake AT comcast DOT net (Eric Blake) To: cygwin AT cygwin DOT com Cc: Stan Tsu Subject: Re: basename(1) defect Date: Thu, 24 Nov 2005 00:26:02 +0000 Message-Id: <112420050026.17376.4385089A000BF9BE000043E022069997350A050E040D0C079D0A@comcast.net> Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com > > This is a bug with basename 5.3.0 found in the latest Cygwin 1.5.15.1. Not a bug. > > 1.5.15 was three releases ago, it's most certainly not the latest. But > that's not really relevant to your question, I don't think. > > > $ basename NA A > > N > > $ basename N/A A > > A <====== should return 'N/' POSIX requires that basename return everything beyond the final slash onwards, minus a partial suffix. The output you got is REQUIRED by basename (beyond the final suffix is "A", and "A" is a complete match rather than a partial suffix of "A", so the result must be "A"), and any other behavior from an older version of basename would be the bug, not the current behavior of either basename-5.3.0 or basename-5.93. > > > > Even with quoting: > > > > $ basename 'NA' A > > N > > $ basename 'N/A' A > > A <====== should return 'N/' Quoting makes no difference - the shell strips quotes before passing the arguments to /bin/basename. > > If you just want to remove a trailing string I suggest you just use > bash's built in parameter expansion: > > $ FCF="N/A"; Z=${FCF:(-1)}; echo ${FCF%$Z} This could also be done by /bin/expr (if you like coreutils), or even with awk, sed, or perl. But Brian is correct, shell parameter expansion is the most efficient way to do string parsing, as it does not spawn any external processes. -- Eric Blake volunteer cygwin bash/coreutils maintainer -- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Problem reports: http://cygwin.com/problems.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/