Skip to content

Instantly share code, notes, and snippets.

@shapr
Created September 7, 2019 20:54
Show Gist options
  • Save shapr/7c0fe351f78da33505f640b1b3e12ffe to your computer and use it in GitHub Desktop.
Save shapr/7c0fe351f78da33505f640b1b3e12ffe 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