Created
September 7, 2019 20:54
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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