Hacker News new | ask | show | jobs
by eximius 3934 days ago
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.

2 comments

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.

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.
Sure, but you could compile:

    #include <my_api.h>
    
    int main() { return 0; }
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.

C# has REPL in the immediate window when the debugger is running; so it's kind of like using GDB as a REPL for C. Although it is somewhat limited in what you can do.
That's actually really good to know about.

Visual Studio's a little bit heavyweight, but if you're programming C#, there's a good chance that's what you're using anyway.

beanshell is quite painful. I like using the repl of a jvm language to explore classes and methods. Like slime+clojure or groovysh or jruby.
Reminds me of vxworks: the main shell for the operating system is the debugger.
When I need a C repl, I often use python and ctypes.