A foreign function interface for bash.
C Shell M4 Other
Latest commit b5f5cf0 Jul 30, 2016 @taviso committed on GitHub Merge pull request #42 from jwilk/spelling
Fix typos
Permalink
Failed to load latest commit information.
build-aux clean up some autoconf files Jun 24, 2016
include
lib define atribute pure for FreeBSD issue #35 Jul 13, 2016
m4 clean up some autoconf files Jun 24, 2016
src
test fix test localization for issue #36, and close issue #37 Jul 19, 2016
.gitignore move libstruct into own compilation unit Jun 26, 2016
.hgignore
AUTHORS
COPYING Automake and libtool support Aug 5, 2015
ChangeLog Automake and libtool support Aug 5, 2015
Makefile.am make sure the new struct headers are included in make dist Jul 17, 2016
NEWS update documentation Jul 17, 2016
README Automake and libtool support Aug 5, 2015
README.md update documentation Jul 17, 2016
TODO Only print results to stderr when the shell is interactive. Aug 6, 2015
autogen.sh Automake and libtool support Aug 5, 2015
configure fix broken configure Jun 26, 2016
configure.ac bump version to 1.1 Jul 17, 2016
ctypes.sh.in

README.md

ctypes.sh

This is ctypes.sh, a foreign function interface for bash.

ctypes.sh is a bash plugin that provides a foreign function interface directly in your shell. In other words, it allows you to call routines in shared libraries from within bash.

A (very) simple example will help illustrate:

$ dlcall puts "hello, world"
hello, world

# A more complex example, use libm to calculate sin(PI/2)
$ dlopen libm.so.6
0x172ebf0
$ dlcall -r double sin double:1.57079632679489661923
double:1.000000

ctypes.sh can extend bash scripts to accomplish tasks that were previously impossible, or would require external helpers to be written.

ctypes.sh makes it possible to use GTK+ natively in your shell scripts, or write a high-performance http daemon.

See more examples here

prerequisites

ctypes.sh is dependent on the following libraries and programs:

  • libffi
  • bash
  • libelf (optional)
  • elfutils (optional)
  • libdwarf (optional)

install

ctypes.sh can be installed from source like this:

$ git clone https://github.com/taviso/ctypes.sh.git
$ cd ctypes.sh
$ ./autogen.sh
$ ./configure
$ make
$ [sudo] make install

By default ctypes.sh is installed into /usr/local/bin and /usr/local/lib. You can overload the prefix path by defining the PREFIX environment variable before installing.

$ PREFIX=$HOME make install

example

source ctypes.sh
puts () {
  dlcall puts "$@"
  return $?
}

puts "hello, world"

Here is what people have been saying about ctypes.sh:

  • "that's disgusting"
  • "this has got to stop"
  • "you've gone too far with this"
  • "is this a joke?"
  • "I never knew the c could stand for Cthulu."

You can read more about ctypes.sh and see it in action on the Wiki