Skip to content

Instantly share code, notes, and snippets.

@winks
Forked from shapr/Env.hs
Created September 14, 2019 18:36
Show Gist options
  • Save winks/a8daf80e48e7056a62725faca015434e to your computer and use it in GitHub Desktop.
Save winks/a8daf80e48e7056a62725faca015434e to your computer and use it in GitHub Desktop.
lookup environment variables, some of which do not exist. Handle whether exists or not.
module Main where
-- using http://hackage.haskell.org/package/base-4.12.0.0/docs/System-Environment.html#v:lookupEnv
import System.Environment
main :: IO ()
main = do
shell <- lookupEnv "SHELL" -- System.Environment.lookupEnv take a String
doesnotexist <- lookupEnv "DOESNOTEXIST"
print (checkEnvVars shell)
print (checkEnvVars doesnotexist)
checkEnvVars :: Maybe String -> String
checkEnvVars Nothing = "This value does not exist"
checkEnvVars (Just v) = "The enviroment has this, value is " <> v
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment