Live data from Hacker News

Ctypes.sh – A foreign function interface for bash

ctypes.sh

1–10 of 39 posts

Re: Ctypes.sh – A foreign function interface for bash

#3
post #2

What could go wrong? /s All sarcasm aside, a very interesting idea. I'm not sure what the proper use case is, but I'm sure someone will love this.

The best use-case I can think of is using bash as a REPL for C libraries. Many times in the past, I've made library calls that either misinterpreted the parameters or the result value. I would have loved the ability to prototype those calls in bash until I understood them enough to call them properly.

Re: Ctypes.sh – A foreign function interface for bash

#4
post #2

What could go wrong? /s All sarcasm aside, a very interesting idea. I'm not sure what the proper use case is, but I'm sure someone will love this.

There are a couple of weird APIs like unshare(2) where it matters that you do things in the shell itself, not in a process spawned by a shell. (chdir(2) might be an even better example, come to think of it.) I once wrote a bash plugin for playing with unshare(2) specifically.

That said, unshare(1) now supports `-r` with `-U`, which was the thing I needed.

Re: Ctypes.sh – A foreign function interface for bash

#5
Neat...and on a somewhat similar note (bash enable -f hacks), some bash FUSE bindings I wrote a few years back: https://github.com/zevweiss/booze

I initially wrote it basically just for giggles, but was rather pleased a few months ago when I realized I could use it for something I actually needed, and it was just the right thing (presenting a mount point that acted as a view of the differences between two rsnapshot-style hard-link trees -- only took a few dozen lines of very simple code).

Re: Ctypes.sh – A foreign function interface for bash

#6
post #2

What could go wrong? /s All sarcasm aside, a very interesting idea. I'm not sure what the proper use case is, but I'm sure someone will love this.

The best use-case I can think of is using bash as a REPL for C libraries. Many times in the past, I've made library calls that either misinterpreted the parameters or the result value. I would have loved the ability to prototype those calls in bash until I understood them enough to call them properly.

You can use gdb as an REPL for C.

Re: Ctypes.sh – A foreign function interface for bash

#8

Earlier quoted context omitted.

The best use-case I can think of is using bash as a REPL for C libraries. Many times in the past, I've made library calls that either misinterpreted the parameters or the result value. I would have loved the ability to prototype those calls in bash until I understood them enough to call them properly.

You can use gdb as an REPL for C.

This blew my mind the first time some one showed me, and is one of the reasons I currently prefer C to other mainstream compiled languages.

Edit: I suppose it is possible to get some version of a repl with C++ (Cling?), Java (Beanshell, Java 9?), C# (Mono, but not currently .Net?). But each of those seems generally a bit harder to get access to than simply calling gdb on a binary with debugging symbols enabled.

Re: Ctypes.sh – A foreign function interface for bash

#9

Earlier quoted context omitted.

The best use-case I can think of is using bash as a REPL for C libraries. Many times in the past, I've made library calls that either misinterpreted the parameters or the result value. I would have loved the ability to prototype those calls in bash until I understood them enough to call them properly.

You can use gdb as an REPL for C.

My gdb-fu is weak, but don't you have to have a binary that you're debugging to do that? I'm thinking of this as more of an exploratory thing-- poking around the edges of an API until I feel comfortable enough with it to start writing real code.

Re: Ctypes.sh – A foreign function interface for bash

#10

Earlier quoted context omitted.

You can use gdb as an REPL for C.

My gdb-fu is weak, but don't you have to have a binary that you're debugging to do that? I'm thinking of this as more of an exploratory thing-- poking around the edges of an API until I feel comfortable enough with it to start writing real code.

Sure, but you could compile:

    #include 
    
    int main() { return 0; }
Post reply on HN