[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: document AS_BASENAME
From: |
Paul Eggert |
Subject: |
Re: document AS_BASENAME |
Date: |
Thu, 30 Mar 2006 22:12:35 -0800 |
User-agent: |
Gnus/5.1007 (Gnus v5.10.7) Emacs/21.4 (gnu/linux) |
Stepan Kasal <address@hidden> writes:
> Are there buggy implementations of basename? If yes, how can be they
> distinguished?
Sorry, I don't recall all the details.
> I tried to resolve all the points above, see the attached patch.
Thanks, I installed the following, which I hope addresses all the
issues that you and others raised. (For extra trivia credit, explain
why the '?' is needed in the patch below. :-)
2006-03-30 Paul Eggert <address@hidden>
* doc/autoconf.texi (Programming in M4sh, Limitations of Usual Tools):
Tighten up the basename/dirname wording.
--- autoconf.texi 30 Mar 2006 19:54:08 -0000 1.974
+++ autoconf.texi 31 Mar 2006 06:08:36 -0000 1.975
@@ -9386,9 +9386,9 @@ that unfortunately are not portable in p
@defmac AS_BASENAME (@var{file-name})
@asindex{BASENAME}
Output the non-directory portion of @var{file-name}. For example,
address@hidden([/one/two/three])} outputs @samp{three}.
address@hidden of Usual Tools}, for more details about what this
-returns and why it is more portable than the @command{basename} command.
address@hidden([/one/two/three])`} sets @code{file} to
address@hidden @xref{Limitations of Usual Tools}, for why this is more
+portable than @command{file=`basename /one/two/three`}.
@end defmac
@defmac AS_BOURNE_COMPATIBLE
@@ -9409,9 +9409,9 @@ corresponding pattern matched @var{word}
@defmac AS_DIRNAME (@var{file-name})
@asindex{DIRNAME}
Output the directory portion of @var{file-name}. For example,
address@hidden([/one/two/three])} outputs @samp{/one/two}.
address@hidden of Usual Tools}, for more details about what this
-returns and why it is more portable than the @command{dirname} command.
address@hidden([/one/two/three])`} sets @code{file} to
address@hidden/one/two}. @xref{Limitations of Usual Tools}, for why this is
+more portable than @command{file=`dirname /one/two/three`}.
@end defmac
@defmac AS_IF (@var{test1}, @ovar{run-if-true1}, @dots{}, @ovar{run-if-false})
@@ -12183,11 +12183,21 @@ fields in a record. You may be able to
@c ---------------------
@prindex @command{basename}
Not all hosts have a working @command{basename}, and you should instead
-use @code{AS_BASENAME} (@pxref{Programming in M4sh}). For example:
+use @code{AS_BASENAME} (@pxref{Programming in M4sh}), followed by
address@hidden if you need to strip a suffix. For example:
@example
-file=`basename "$file"` # This is not portable.
-file=`AS_BASENAME(["$file"])` # This is more portable.
+a=`basename "$aname"` # This is not portable.
+a=`AS_BASENAME(["$aname"])` # This is more portable.
+
+# This is not portable.
+c=`basename "$cname" .c`
+
+# This is more portable.
+c=`AS_BASENAME(["$cname"])`
+case $c in
+?*.c) c=`expr "X$c" : 'X\(.*\)\.c'`;;
+esac
@end example