I recently had occasion to refactor a bunch of bash scripts, and one of the problems was that certain loop constructs were cropping up a lot. A quick search didn't turn up a way to do higher order functions in bash, so I (re)invented one:
higher_order() {
# some code
eval "$1"
# some more code
}The eval evaluates the code passed as a
(
Read more... )
Comments 4
Of course, all my mIRC script messing around culminated in the PiBot, so there's clearly risk involved.
Reply
I wouldn't use most of this stuff in anger, though. By the time it's necessary, I've usually switched to a different language. The only reason I did it in this case was that I was writing system build scripts and I can't assume that anything other than the most basic tools are available.
Reply
You could simply do:
$ FOO="hello world"
$ $FOO
$ $FOO
No?
Alejo, from http://azul.freaks-unidos.net/
Reply
Reply
Leave a comment