Skip to content
Search

Haskell:System.Environment

lastmod 2020-09-27created 2020-09-274 edits

Miscellaneous information about the system environment.

Synopsis

getArgs :: IO [String]
getProgName :: IO String
getExecutablePath :: IO FilePath
getEnv :: String -> IO String
lookupEnv :: String -> IO (Maybe String)
setEnv :: String -> String -> IO ()
unsetEnv :: String -> IO ()
withArgs :: [String] -> IO a -> IO a
withProgName :: String -> IO a -> IO a
getEnvironment :: IO [(String, String)]

lookupEnv

lookupEnv :: String -> IO (Maybe String)

Returns the value of the environment variable var, or Nothing if there is no such value.

For POSIX users, this is equivalent to #getEnv.

Since: 4.6.0.0

Example

import System.Environment

main = do
    setEnv "FOO" "1"
    putStr "FOO:" >> (putStrLn  =<< getEnv "FOO")
    putStr "BAR:" >> (print  =<< lookupEnv "BAR")
    putStrLn ""
    mapM_ putStrLn =<< map fst `fmap` getEnvironment

See also

Favorite site

author Zer0 sitemap