Multiline shebang: Difference between revisions

Added two Haskell examples.
m (be tolerant of changes in current locale)
(Added two Haskell examples.)
Line 196:
}
</lang>
 
=={{header|Haskell}}==
 
{{trans|C}}
 
<lang Haskell>#!/bin/bash
sed -n -e '7,$p' < "$0" > $0.$$.hs
ghc $0.$$.hs > /dev/null
./$0.$$ "$0" "$@"
rm $0.$$*
exit
import Text.Printf
import System.Environment
 
main :: IO ()
main = getArgs >>= mapM_ (uncurry $ printf "argv[%d] -> %s\n") . zip ([0..] :: [Int])</lang>
 
{{out}}
 
<pre>$ ./multibang.hs
argv[0] -> ./multibang.hs
$ ./multibang.hs Goodbye, World!
argv[0] -> ./multibang.hs
argv[1] -> Goodbye,
argv[2] -> World!</pre>
 
Or you can 'cheat' by ignoring Bash's complaints about Haskell comments (gives the exact same output as above):
 
<lang Haskell>#!/bin/bash
{- 2> /dev/null
exec runghc $0 $0 $@
-}
import Text.Printf
import System.Environment
 
main :: IO ()
main = getArgs >>= mapM_ (uncurry $ printf "argv[%d] -> %s\n") . zip ([0..] :: [Int])</lang>
 
=={{header|J}}==
Anonymous user