[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: "make check" failure [with "." at beginning of PATH]
From: |
Jim Meyering |
Subject: |
Re: "make check" failure [with "." at beginning of PATH] |
Date: |
Sun, 10 Feb 2008 13:48:49 +0100 |
Bruno Haible <address@hidden> wrote:
> Jim Meyering wrote:
>> +# Emulate dirname with sed.
>> +# This approximation fails when the input is a single-component
>> +# absolute directory name like /foo, but that never happens here.
>> +approx_dirname_filter = sed 's,^[^/]*$$,.,;s,//*[^/]*$$,,'
>
> Oops, sorry for suggesting a bad approximation. Here's a better one:
> approx_dirname_filter = sed
> 's,^[^/]*$$,.,;s,^/[^/]*$$,/,;s,\([^/]\)//*[^/]*$$,\1,'
>
> Tested like this:
> $ { echo abc; echo abc/def ; echo / ; echo /doo; echo /foo/bar; echo //foo; }
> \
> | sed 's,^[^/]*$,.,;s,^/[^/]*$,/,;s,\([^/]\)//*[^/]*$,\1,'
> .
> abc
> /
> /
> /foo
> //foo
Thanks. That's better. However, it doesn't change //foo.
If I make a change for the sake of completeness,
I'd prefer that it map //foo to /, like dirname does.
In the same vein, we might as well make it strip trailing slashes
and thus map ///a/// to / (rather than to ///a).
I expect to use this instead:
_d_no_slash = s,^[^/]*$$,.,
_d_strip_trailing = s,\([^/]\)//*$$,\1,
_d_abs_trivial = s,^//*[^/]*$$,/,
_d_rm_basename = s,\([^/]\)//*[^/]*$$,\1,
_dirname = \
sed '$(_d_no_slash);$(_d_strip_trailing);$(_d_abs_trivial);$(_d_rm_basename)'
Tested like this:
for i in d/f /d/f d/f/ f / // //d /// ///a///; do d=$(dirname $i)
r=$(echo $i| sed \
's,^[^/]*$,.,;s,\([^/]\)//*$,\1,;s,^//*[^/]*$,/,;s,\([^/]\)//*[^/]*$,\1,')
test $d = $r || printf "input: $i\nexpect: $d\nactual: $r\n"; done