From: Akim Demaille <[EMAIL PROTECTED]>
   Date: 01 Aug 2000 14:52:47 +0200

   Why don't we use AWK?  I know it's not in the standards, but are
   there any good reasons for this?

We could use AWK as a fallback if the standard tools fail.  However, I
think we can do it with the standard tools.  The following works for
me, using Solaris 8 /usr/ucb/expr (sorry, I no longer have a SunOS 4
host to test with).

        # Prefer expr to sed, since it's usually faster and it handles
        # newlines correctly.  However, SunOS 4 expr and Solaris
        # /usr/ucb/expr have a silly length limit that causes expr to
        # fail if the matched substring is longer than 128 bytes.
        # So use sed if expr fails.
        dirname=`expr "X$filename" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
              "X$filename" : 'X\(//\)[^/]' \| \
              "X$filename" : 'X\(//\)$' \| \
              "X$filename" : 'X\(/\)' \| \
              . : '\(.\)' \
              2>/dev/null` ||
        dirname=`
          sed '
            /^\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/p; q; }
            /^\(\/\/\)[^/].*/{ s//\1/p; q; }
            /^\(\/\/\)$/{ s//\1/p; q; }
            /^\(\/\).*/{ s//\1/p; q; }
            s/.*/./p; q
          ' <<EOF
$filename
EOF
        `

Reply via email to