Live data from Hacker News

Pnut: A C to POSIX shell compiler you can trust

pnut.sh

1–10 of 124 posts

Re: Pnut: A C to POSIX shell compiler you can trust

#3
post #2

It's a bad sign when I immediately look at the screenshot and see quoting bugs.

Author here,

Because all shell variables in code generated by pnut are numbers, variables never contain whitespace or special characters and don't need to be quoted. We considered quoting all variable expansions as this is generally seen as best practice in shell programming, but thought it hurt readability and decided not to.

If you think there are other issues, please let me know!

Re: Pnut: A C to POSIX shell compiler you can trust

#6

I was puzzled by the example C function containing pointers. Do I understand correctly that you implement pointers in shell by having a shell variable _0 for the first "byte" of "memory", a shell variable _1 for the second, etc.?

Author here,

That's correct! Unlike Bash and other modern shells, the POSIX standard doesn't include arrays or any other data structures. The way we found around this limitation is to use arithmetic expansion and indexed shell variables (that are starting with `_` as you noted) to get random memory access.

Re: Pnut: A C to POSIX shell compiler you can trust

#7
Hrmmm. But why?

Quite frankly I think Bash scripting is awful and frequently wish shell scripts were written in a real and debuggable language. For anything non-trivial that is.

I feel like I’d rather write C and compile it with Cosmopolitan C to give me a cross-platform binary than this.

Neat project. Definitely clever. But it’s headed in the opposite direction from what I’d prefer...

Re: Pnut: A C to POSIX shell compiler you can trust

#8
Looking forward to the point where this can build autoconf. It's great that the generated ./configure script is portable but if I want to make substantial changes to the project I need to find a binary for my machine (and version differences can be quite substantial)

Re: Pnut: A C to POSIX shell compiler you can trust

#9
post #8

Looking forward to the point where this can build autoconf. It's great that the generated ./configure script is portable but if I want to make substantial changes to the project I need to find a binary for my machine (and version differences can be quite substantial)

This is going further into the hell that is shell-generated scripts that culminated in the xz-utils attack.

We would benefit from steering away from auto-generated scripts. Autoconf included.

Post reply on HN