>>>>> "Alexandre" == Alexandre Oliva <[EMAIL PROTECTED]> writes:
Alexandre> Try this one:
>> al=`echo $dir | sed
>> '/^\/*$/!s%//*$%%;s%[^/]*$%%;s%//*$%/%;/^\/$/!s%/$%%'`
Almost right :)
~/src/ace % cat /tmp/dirname.sh nostromo 10:59
#! /bin/sh
format="%12s %12s %12s %12s %12s\n"
# autoconf, alexandre, texi2dvi, GNU dirname
printf "$format" "" ac al tx dn
for dir in //tmp /tmp ./tmp ../../here \
//tmp/ /tmp/ ./tmp/ ../../here \
//tmp/2 /tmp/2 ./tmp/2 ../../here/2 \
//tmp/2// /tmp/2// ./tmp/2// ../../here/2//
do
ac=`echo $dir | sed 's%/[^/][^/]*$%%'`
al=`echo $dir | sed '/^\/*$/!s%//*$%%;s%[^/]*$%%;s%//*$%/%;/^\/$/!s%/$%%'`
tx=`echo $dir | sed 's!/[^/]*$!!;s!^$!.!'`
dn=`command dirname $dir`
printf "$format" "$dir" "$ac" "$al" "$tx" "$dn"
done
~/src/ace % sh /tmp/dirname.sh nostromo 11:00
ac al tx dn
//tmp / / / /
/tmp / . /
./tmp . . . .
../../here ../.. ../.. ../.. ../..
//tmp/ //tmp/ / //tmp /
/tmp/ /tmp/ / /tmp /
./tmp/ ./tmp/ . ./tmp .
../../here ../.. ../.. ../.. ../..
//tmp/2 //tmp //tmp //tmp //tmp
/tmp/2 /tmp /tmp /tmp /tmp
./tmp/2 ./tmp ./tmp ./tmp ./tmp
../../here/2 ../../here ../../here ../../here ../../here
//tmp/2// //tmp/2// //tmp //tmp/2/ //tmp
/tmp/2// /tmp/2// /tmp /tmp/2/ /tmp
./tmp/2// ./tmp/2// ./tmp ./tmp/2/ ./tmp
../../here/2// ../../here/2// ../../here ../../here/2/ ../../here