diff --git a/libraries/gen_contents_index b/libraries/gen_contents_index
index 393a8790fcd7e6dca1b2cf3a8cf0beafa862db05..fd9048b0be54b9e9b0df771ee4389579cf84bb65 100644
--- a/libraries/gen_contents_index
+++ b/libraries/gen_contents_index
@@ -10,7 +10,7 @@ case $* in
     GHC_PKG=../utils/ghc-pkg/ghc-pkg-inplace
     for DIR in */
     do
-        NAME=${DIR%/}
+        NAME=`echo "$DIR" | sed 's#/$##'`
         HADDOCK_FILE=$NAME/dist/doc/html/$NAME/$NAME.haddock
         if [ -f $HADDOCK_FILE ]
         then