[英]haskell and Unix shell scripting
is there any possibility to use haskell functions in unix shell scripts? 是否有可能在unix shell脚本中使用haskell函数?
for instance: 例如:
#!/bin/bash
...
var1=value
...
# use haskell function with input from shell variable var1
# and store the result into another shell variable var2
var2=haskellFunction $var1
...
I want to use variables in shell scripts as arguments and results of haskell functions 我想在shell脚本中使用变量作为haskell函数的参数和结果
Thanks in advance. 提前致谢。
jimmy 吉米
Use the -e
switch to ghc
, eg 使用-e
开关到ghc
,例如
var2=$(ghc -e "let f x = x*x + x/2 in f $var1")
For string processing, it is best to use Haskell's interact
in conjunction with bash's here strings: 对于字符串处理,最好将Haskell的interact
与bash的字符串结合使用:
var2=$(ghc -e 'interact reverse' <<<$var1)
Also, you can write scripts using ghci
: Just put shebang #!/usr/bin/env runhaskell
at the first line of the script and make it executable. 此外,您可以使用ghci
编写脚本:只需将shebang #!/usr/bin/env runhaskell
放在脚本的第一行并使其可执行。 Such scripts may be called from sh/bash/ksh/csh/whatever
scripts as usual. 这些脚本可以像往常一样从sh/bash/ksh/csh/whatever
脚本调用。
Eg 例如
$ cat > hello.hsh
#!/usr/bin/env runhaskell
main = putStrLn "Hello world!"
$ chmod +x hello.hsh
$ ./hello.hsh
Hello world!
$
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.