>>>>> "Martin" == Martin Wilck <[EMAIL PROTECTED]> writes:

>> > al=`echo $dir | sed
>> '/^\/*$/!s%//*$%%;s%[^/]*$%%;s%//*$%/%;/^\/$/!s%/$%%'` ^^^^^^^^^^
>> ^^
Martin>
Martin> ^ I think "!" after a sed address expression is not portable -
Martin> actually, it seems to work only with GNU sed.

Hm, I've used this many times, and have never been trapped.  Which sed
are you thinking about?

This is about the most broken machine I have an access to:

login: akim
Password:
RISC/os (UMIPS) 4.52 krypton
(C) Copyright 1986-1990, MIPS Computer Systems
All Rights Reserved
bash$ cat /tmp/dirname.sh
#! /bin/sh
          
format="%12s %12s %12s %12s %12s\n"
                                   
# autoconf, alexandre, texi2dvi, GNU dirname
echo "" ac tx al dn                         
                   
for dir in //1 /1 ./1 ../../2 \
           //1/ /1/ ./1/ ../../2 \
           //1/3 /1/3 ./1/3 ../../2/3 \
           //1/3/// /1/3/// ./1/3/// ../../2/3/// \
           //1//3/ /1//3/ ./1//3/ ../../2//3/      
do                                           
  al=`echo $dir | sed '/^\/*$/!s%//*$%%;s%[^/]*$%%;s%//*$%/%;/^\/$/!s%/$%%'`
  dn=`dirname $dir`                                                         
  echo "$dir        $al     $dn"
done                            
bash$ sh /tmp/dirname.sh 
 ac tx al dn
//1     /       /
/1      /       /
./1     .       .
../../2 ../..   ../..
//1/    /       /    
/1/     /       /
./1/    .       .
../../2 ../..   ../..
//1/3   //1     //1  
/1/3    /1      /1 
./1/3   ./1     ./1
../../2/3       ../../2 ../../2
//1/3///        //1     //1    
/1/3/// /1      /1         
./1/3///        ./1     ./1
../../2/3///    ../../2 ../../2
//1//3/ //1     //1            
/1//3/  /1      /1 
./1//3/ ./1     ./1
../../2//3/     ../../2 ../../2

Reply via email to