1 changed files with 25 additions and 0 deletions
@ -0,0 +1,25 @@ |
|||||||
|
{-# LANGUAGE NoImplicitPrelude #-} |
||||||
|
|
||||||
|
import Prelude (IO, String, ($), (.), (++), (/=), (==), (||), |
||||||
|
filter, head, map, mapM_, null, otherwise, putStr, |
||||||
|
putStrLn, tail) |
||||||
|
import Control.Monad ((>>=)) |
||||||
|
import Data.Maybe (fromMaybe) |
||||||
|
import System.Environment (getArgs, getEnvironment, lookupEnv) |
||||||
|
import System.IO.Unsafe (unsafePerformIO) |
||||||
|
|
||||||
|
env :: String -> String |
||||||
|
env = fromMaybe [] . unsafePerformIO . lookupEnv |
||||||
|
|
||||||
|
printenvs :: (String -> IO ()) -> [String] -> IO () |
||||||
|
printenvs fx [] = mapM_ fx [k ++ "=" ++ v | (k, v) <- unsafePerformIO getEnvironment] |
||||||
|
printenvs fx vars = mapM_ fx (filter (/= []) $ map env vars) |
||||||
|
|
||||||
|
printenv :: [String] -> IO () |
||||||
|
printenv str | null str = printenvs putStrLn [] |
||||||
|
| head str == "--null" || head str == "-0" = printenvs putStr (tail str) |
||||||
|
| otherwise = printenvs putStrLn str |
||||||
|
|
||||||
|
main :: IO () |
||||||
|
main = getArgs >>= printenv |
||||||
|
|
Loading…
Reference in new issue