runCompound b (Case expr cases) = do e <- expandWord expr
                                     run e cases
    where run _ [] = return ExitSuccess
          run s ((ps,cs):xs) = do match <- check s ps
                                  if match then runCommands' b cs
                                           else run s xs
          check _ [] = return False
          check s (p:ps) = do p' <- expandPattern p
                              if matchPattern p' s then return True
                                                   else check s ps
runCompound b (Case expr cases) = do e <- expandWord expr
                                     run e cases
    where run _ [] = return ExitSuccess
          run s ((ps,cs):xs) = do match <- check s ps
                                  if match then runCommands' b cs
                                           else run s xs
          check _ [] = return False
          check s (p:ps) = do p' <- expandPattern p
                              if matchPattern p' s then return True
                                                   else check s ps
runCompound b (Case expr cases) = do e <- expandWord expr
                                     run e cases
    where run _ [] = return ExitSuccess
          run s ((ps,cs):xs) = do match <- check s ps
                                  if match then runCommands' b cs
                                           else run s xs
          check _ [] = return False
          check s (p:ps) = do p' <- expandPattern p
                              if matchPattern p' s then return True
                                                   else check s ps