Hello!

On Fri, May 28, 1999 at 08:00:27AM +0200, Friedrich Dominicus wrote:
> I wrote before with my trouble understanding hugsIsEOF. But I don't have
> found a clean way just to write a cat. Can s.o give me a hand?

import System(getArgs)
file2stdout :: String {- filename -} -> IO ()
file2stdout filename = do
    let realname = case filename of "-" -> "/dev/stdin"; _ -> filename
    content <- readFile realname
    putStr content

main = do
    args <- getArgs
    case args of
        [] -> file2stdout "-"
        _  -> mapM_ file2stdout args

Due to lazy evaluation and the laziness of readFile, the file won't be
sucked in completely before outputting, but will be read in chunks.

That program just doesn't support the usual cat options
(cat [-benstuv] [file | - ...]).

Regards, Hannah.


Reply via email to