Re: what platforms don't have `dirname`?

Paul Eggert <[email protected]>
Newsgroups gmane.comp.sysutils.autoconf.bugs
Organization UCLA Computer Science Department
Message-ID <[email protected]>
On 7/21/22 10:22, Werner LEMBERG wrote:
> 
> it seems to me
> that the advice, while useful for autoconf, is very outdated.

Thanks, I installed the attached.
0001-basename-and-dirname-are-portable-now.patch (text/x-patch, 2.2 KB)
From 949e49297940529d2803a274617af8951f18e82b Mon Sep 17 00:00:00 2001
From: Paul Eggert <[email protected]>
Date: Thu, 21 Jul 2022 12:49:50 -0700
Subject: [PATCH] basename and dirname are portable now

* doc/autoconf.texi (Limitations of Usual Tools):
basename and dirname are portable shell commands now.
---
 doc/autoconf.texi | 21 +++++++++++++++------
 1 file changed, 15 insertions(+), 6 deletions(-)

diff --git a/doc/autoconf.texi b/doc/autoconf.texi
index fdc662e1..fa5a9f48 100644
--- a/doc/autoconf.texi
+++ b/doc/autoconf.texi
@@ -14065,6 +14065,9 @@ Output the directory portion of @var{file-name}.  For example,
 if @code{$file} is @samp{/one/two/three}, the command
 @code{dir=`AS_DIRNAME(["$file"])`} sets @code{dir} to @samp{/one/two}.
 
+@code{AS_DIRNAME} was designed long ago when
+the @command{dirname} command was not universally supported.
+Nowadays one can safely use @code{dir=`dirname -- "$file"`} instead.
 This interface may be improved in the future to avoid forks and losing
 trailing newlines.
 @end defmac
@@ -19139,8 +19142,13 @@ of at most 3070 bytes.
 @item @command{basename}
 @c ---------------------
 @prindex @command{basename}
-Not all hosts have a working @command{basename}.
-You can use @command{expr} instead.
+Long ago some hosts lacked a working @command{basename},
+and portable scripts needed to use @command{expr} instead.
+Nowadays it is safe to use @command{basename}.  For example:
+
+@example
+base=`basename -- "$file"`
+@end example
 
 @c AS_BASENAME is to be replaced by a better API.
 @ignore
@@ -19331,12 +19339,13 @@ Some implementations, such as Tru64's, fail when comparing to
 @item @command{dirname}
 @c --------------------
 @prindex @command{dirname}
-Not all hosts have a working @command{dirname}, and you should instead
-use @code{AS_DIRNAME} (@pxref{Programming in M4sh}).  For example:
+Long ago some hosts lacked a working @command{dirname} and portable
+scripts needed to use use @code{AS_DIRNAME} (@pxref{Programming in M4sh}).
+Nowadays @command{dirname} suffices and the following are equivalent:
 
 @example
-dir=`dirname "$file"`       # This is not portable.
-dir=`AS_DIRNAME(["$file"])` # This is more portable.
+dir=`dirname -- "$file"`
+dir=`AS_DIRNAME(["$file"])`
 @end example
 
 
-- 
2.34.1
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.