I’m using getArgs in my Haskell program to parse arguments from the command line. However, I’ve noticed that I have problems when I call my program like this:
runhaskell Main *.hs .
As you can imagine, Main looks at *.hs files in the . directory.
But there’s a problem. The code below doesn’t behave as I’d expect.
import System
main :: IO ()
main = do
args <- getArgs
print args
I want to see
args = ["*.hs","."]
but instead I see
args = ["file1.hs","file2.hs","file3.hs","."]
My program needs to expand the glob expression itself because it does it in multiple directories. But how can I have getArgs return the raw list of arguments instead of trying to be magical and do the parsing itself?
This isn’t haskell, this is your shell.
Normally file globs (like
*.hs) are interpreted by the shell before the command is passed to haskell.To see this try running
The single quotes will prevent your shell from interpreting the glob, and pass the argument as-is to
runhaskell.