Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

haskell and Unix shell scripting

is there any possibility to use haskell functions in unix shell scripts?

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

Thanks in advance.

jimmy

like image 577
jimmyt Avatar asked Nov 04 '12 19:11

jimmyt


People also ask

Is Haskell good for scripting?

Right now dynamic languages are popular in the scripting world, to the dismay of people who prefer statically typed languages for ease of maintenance. Fortunately, Haskell is an excellent candidate for statically typed scripting for a few reasons: Haskell has lightweight syntax and very little boilerplate.

Is shell script a programming language?

A Unix shell is both a command interpreter and a programming language. As a command interpreter, the shell provides the user interface to the rich set of GNU utilities.

What is shh in programming?

[ bsd3, library, program, system ] [ Propose Tags ] Provides a shell scripting environment for Haskell. It helps you use external binaries, and allows you to perform many shell-like functions, such as piping and redirection.


1 Answers

Use the -e switch to ghc, e.g.

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:

var2=$(ghc -e 'interact reverse' <<<$var1)
like image 166
dave4420 Avatar answered Nov 08 '22 19:11

dave4420