This page is no longer maintained — Please continue to the home page at www.scala-lang.org

scala in bash

3 replies
extempore
Joined: 2008-12-17,
User offline. Last seen 35 weeks 3 days ago.

I'm proud of this one so I will take the unusual step of actually
telling someone about code I've written.

https://github.com/paulp/scalabash

Example from README:

# The % is a marker for each incoming argument
bash> printf "1\n2\n3\n" | foreach-stdin echo a b % d e
a b 1 d e
a b 2 d e
a b 3 d e

If you look under the hood there is some pretty sick stuff going on. I
think it can be simplified a bit, but the key idea is the implementation
of closure-like things with eval. For the most part the ideas are other
peoples', but I couldn't find anyone who had packaged everything up such
that I could run a pipeline through foreach (or we could call it map,
it's not like there's an amazing difference in bash) like the gods intended.

Stefan Wagner
Joined: 2011-04-08,
User offline. Last seen 42 years 45 weeks ago.
Re: scala in bash

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Am 11.08.2011 21:15, schrieb Paul Phillips:
> a b 1 d e

Pure bash:

echo -e "a b "{1..3}" d e\n"
a b 1 d e
a b 2 d e
a b 3 d e

looks more simple

extempore
Joined: 2008-12-17,
User offline. Last seen 35 weeks 3 days ago.
Re: scala in bash

On 8/14/11 10:26 PM, Stefan Wagner wrote:
> looks more simple

Can't tell if you're joking. The goal wasn't to write software which
produces that exact output. I know that "a b 1 d e" comes up a lot, but
sometimes we have to do other things too.

Note to self: include fancier examples of what one might do with
anonymous functions.

Stefan Wagner
Joined: 2011-04-08,
User offline. Last seen 42 years 45 weeks ago.
Re: scala in bash

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Am 15.08.2011 17:11, schrieb Paul Phillips:
> On 8/14/11 10:26 PM, Stefan Wagner wrote:
>> looks more simple
>
> Can't tell if you're joking. The goal wasn't to write software which
> produces that exact output. I know that "a b 1 d e" comes up a lot, but
> sometimes we have to do other things too.

I'm always joking, and never.

I think to show the usefulness of your software, it should have one or
more examples, which are harder to do without it.
So I allowed myself to show you, that that example isn't so strong.

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland