frontpage.
newsnewestaskshowjobs

Made with ♥ by @iamnishanth

Open Source @Github

fp.

OpenCiv3: Open-source, cross-platform reimagining of Civilization III

https://openciv3.org/
553•klaussilveira•10h ago•157 comments

The Waymo World Model

https://waymo.com/blog/2026/02/the-waymo-world-model-a-new-frontier-for-autonomous-driving-simula...
876•xnx•15h ago•532 comments

How we made geo joins 400× faster with H3 indexes

https://floedb.ai/blog/how-we-made-geo-joins-400-faster-with-h3-indexes
79•matheusalmeida•1d ago•18 comments

What Is Ruliology?

https://writings.stephenwolfram.com/2026/01/what-is-ruliology/
8•helloplanets•4d ago•3 comments

Unseen Footage of Atari Battlezone Arcade Cabinet Production

https://arcadeblogger.com/2026/02/02/unseen-footage-of-atari-battlezone-cabinet-production/
13•videotopia•3d ago•0 comments

Show HN: Look Ma, No Linux: Shell, App Installer, Vi, Cc on ESP32-S3 / BreezyBox

https://github.com/valdanylchuk/breezydemo
191•isitcontent•10h ago•24 comments

Monty: A minimal, secure Python interpreter written in Rust for use by AI

https://github.com/pydantic/monty
190•dmpetrov•10h ago•84 comments

Show HN: I spent 4 years building a UI design tool with only the features I use

https://vecti.com
303•vecti•12h ago•133 comments

Microsoft open-sources LiteBox, a security-focused library OS

https://github.com/microsoft/litebox
347•aktau•16h ago•169 comments

Sheldon Brown's Bicycle Technical Info

https://www.sheldonbrown.com/
347•ostacke•16h ago•90 comments

Dark Alley Mathematics

https://blog.szczepan.org/blog/three-points/
75•quibono•4d ago•16 comments

Hackers (1995) Animated Experience

https://hackers-1995.vercel.app/
444•todsacerdoti•18h ago•226 comments

Show HN: If you lose your memory, how to regain access to your computer?

https://eljojo.github.io/rememory/
242•eljojo•13h ago•148 comments

PC Floppy Copy Protection: Vault Prolok

https://martypc.blogspot.com/2024/09/pc-floppy-copy-protection-vault-prolok.html
46•kmm•4d ago•3 comments

Delimited Continuations vs. Lwt for Threads

https://mirageos.org/blog/delimcc-vs-lwt
17•romes•4d ago•2 comments

An Update on Heroku

https://www.heroku.com/blog/an-update-on-heroku/
379•lstoll•16h ago•258 comments

How to effectively write quality code with AI

https://heidenstedt.org/posts/2026/how-to-effectively-write-quality-code-with-ai/
225•i5heu•13h ago•171 comments

Why I Joined OpenAI

https://www.brendangregg.com/blog/2026-02-07/why-i-joined-openai.html
103•SerCe•6h ago•84 comments

Learning from context is harder than we thought

https://hy.tencent.com/research/100025?langVersion=en
162•limoce•3d ago•85 comments

I spent 5 years in DevOps – Solutions engineering gave me what I was missing

https://infisical.com/blog/devops-to-solutions-engineering
131•vmatsiiako•15h ago•56 comments

Introducing the Developer Knowledge API and MCP Server

https://developers.googleblog.com/introducing-the-developer-knowledge-api-and-mcp-server/
41•gfortaine•8h ago•11 comments

Show HN: R3forth, a ColorForth-inspired language with a tiny VM

https://github.com/phreda4/r3
63•phreda4•9h ago•11 comments

Female Asian Elephant Calf Born at the Smithsonian National Zoo

https://www.si.edu/newsdesk/releases/female-asian-elephant-calf-born-smithsonians-national-zoo-an...
20•gmays•5h ago•3 comments

Show HN: ARM64 Android Dev Kit

https://github.com/denuoweb/ARM64-ADK
14•denuoweb•1d ago•2 comments

Understanding Neural Network, Visually

https://visualrambling.space/neural-network/
262•surprisetalk•3d ago•35 comments

I now assume that all ads on Apple news are scams

https://kirkville.com/i-now-assume-that-all-ads-on-apple-news-are-scams/
1035•cdrnsf•19h ago•428 comments

Zlob.h 100% POSIX and glibc compatible globbing lib that is faste and better

https://github.com/dmtrKovalenko/zlob
6•neogoose•2h ago•3 comments

FORTH? Really!?

https://rescrv.net/w/2026/02/06/associative
56•rescrv•18h ago•19 comments

Show HN: Smooth CLI – Token-efficient browser for AI agents

https://docs.smooth.sh/cli/overview
85•antves•1d ago•63 comments

WebView performance significantly slower than PWA

https://issues.chromium.org/issues/40817676
20•denysonique•6h ago•3 comments
Open in hackernews

Getting decent error reports in Bash when you're using 'set -e'

https://utcc.utoronto.ca/~cks/space/blog/programming/BashGoodSetEReports
166•zdw•6mo ago

Comments

newAccount2025•6mo ago
Why don’t all shells just do this?
inetknght•6mo ago
Perhaps you underestimate just how many scripts are poorly written and part of your operating system.

For what it's worth, I think `set -euo pipefail` should be default for every script, and thoroughly checked with shellcheck.net.

scns•6mo ago
> For what it's worth, I think `set -euo pipefail` should be default for every script, and thoroughly checked with shellcheck.net.

This

mananaysiempre•6mo ago
Take care that set -o pipefail will not work on older dash (including IIRC the current Ubuntu LTS), and neither will set -o pipefail || true if set -e is in effect. (For some reason that I’m too lazy to investigate, a failing set invocation will crash the script immediately rather than proceed into the second branch.) The best I could think of to opportunistically enable it was to use a subshell:

  if (set -o pipefail 2>/dev/null); then set -o pipefail; fi
Or you can just target bash, I guess.

(I rather dislike shellcheck because it combines genuine smells with opinions, such as insisting on $(...) instead of `...`. For the same reason, with Python I regularly use pyflakes but can’t stand flake8. But to each their own.)

koolba•6mo ago
> such as insisting on $(...) instead of `...`.

Only one of those can be (sanely) nested. Why would you ever want to use backticks?

oguz-ismail•6mo ago
Looks slick. Works on older shells too
imcritic•6mo ago
That's a pitfall №60

https://mywiki.wooledge.org/BashPitfalls#set_-euo_pipefail

larkost•6mo ago
I have never liked this statement of the problem.

It is not that `set -e` is bad, it is that bash is a bit weird in this area and you have to know when things eat errors and when they don't. This is not really changed by `set -e`: you already had to know them to make safe code. `set -e` does not wave a magic wand saying you don't have to understand bash error control.

But having `set -e` is almost universally better for people who do not understand it (and I would argue also for people who do). Without it you are responsible for implementing error handling on almost every line.

As other have already said: this is one of those things that generally pushes me to other languages (in my case often Python), as the error handling is much more intuitive, and much less tricky to get right.

fireflash38•6mo ago
One of my major nitpicks with set -e isn't from bash... It's from poorly behaved programs you might run. Ones that don't exit with defined exit codes (non-zero on error!).
inetknght•6mo ago
> Ones that don't exit with defined exit codes (non-zero on error!).

My favorite is `docker images`.

It outputs... not-empty when the output is empty. It returns zero (success) when output is not-empty and empty. So you have to both do error checking and parse its output before you know whether there are any matching images in the cache.

Contrast that with grep. You can do `if grep -q foo` or `if grep -qv foo`, you can do `if "foo" == "$(grep foo)"`, etc. Much more versatile and easy to use.

Then there's apps that report to stderr that some argument isn't used but then also exits with success without doing things. Then there's similar apps that do the same thing but... exits after also doing things. Ugh.

After some time you get to learn to test your apps before you write up scripts around them. That's a good thing though, it means that you know how to mix together a diverse toolset.

javier2•6mo ago
Well, maybe. But using `set -euo pipefail` here does not make it any worse as far as i understand? The script still does broken things, but the more correct way to be safe is not broken by set -euo pipefail
eikenberry•6mo ago
What about for `/bin/sh`, i.e. posix compliant shells like dash?
chasil•6mo ago
Only set -eu is defined in POSIX and supported by dash.
koolba•6mo ago
Automatically leaking the line number and command, even to stderr is not a sane default.
eastbound•6mo ago
Is that a safety point of view? Is shell supposed to be input-safe? I may have limited shell skills but it doesn’t seems like it’s designed to be safe.
fireflash38•6mo ago
Why? It's not like you couldn't get the source of the running script anyway.
forrestthewoods•6mo ago
Because shells weren’t supposed to be doing complex logic. People use shells to do way way way more than they should.
Grimeton•6mo ago
You can just do

  trap 'caller 1' ERR
should do the same thing. Also you should set "errtrace" (-E) and possibly "nounset" (-u) and "pipefail".
gkfasdfasdf•6mo ago
or even use caller to print a full backtrace: https://news.ycombinator.com/item?id=44636927
progbits•6mo ago
That's neat, but if your bash script needs a backtrace it should not be a bash script. To each their own though.
williamdclt•6mo ago
My bash scripts don't "need" a backtrace, but it sure is nicer than not having one
o11c•6mo ago
FWIW, I've grown the following which handles a few more cases. For some reason I wasn't aware of `caller` ...

    set -e

    is-oil()
    {
        test -n "$OIL_VERSION"
    }

    set -E || is-oil

    trap 'echo "$BASH_SOURCE:$LINENO: error: failure during early startup! Details unavailable."' ERR

    magic_exitvalue=$(($(kill -l CONT)+128))

    backtrace()
    {
        {
            local status=$?
            if [ "$status" -eq "$magic_exitvalue" ]
            then
                echo '(omit backtrace)'
                exit "$magic_exitvalue"
            fi
            local max file line func argc argvi i j
            echo
            echo 'Panic! Something failed unexpectedly.' "(status $status)"
            echo 'While executing' "$BASH_COMMAND"
            echo
            echo Backtrace:
            echo
            max=${#BASH_LINENO[@]}
            let max-- # The top-most frame is "special".
            argvi=${BASH_ARGC[0]}
            for ((i=1;i<max;++i))
            do
                file=${BASH_SOURCE[i]}
                line=${BASH_LINENO[i-1]}
                func=${FUNCNAME[i]}
                argc=${BASH_ARGC[i]}
                printf '%s:%d: ... in %q' "$file" "$line" "$func"
                # BASH_ARGV: ... bar foo ...
                # argvi          ^
                # argvi+argc             ^
                for ((j=argc-1; j>=0; --j))
                do
                    printf ' %q' ${BASH_ARGV[argvi+j]}
                done
                let argvi+=argc || true
                printf '\n'
            done

            if true
            then
                file=${BASH_SOURCE[i]}
                line=${BASH_LINENO[i-1]}
                printf '%s:%d: ... at top level\n' "$file" "$line"
            fi
        } >&2
        exit "$magic_exitvalue"
        unreachable
    }
    shopt -s extdebug
    trap 'backtrace' ERR
edoceo•6mo ago
What the hell. This is cool and all but I'm looking at it as a signal I should move up one tier in language (eg: to Perl, PHP, Python or Ruby)
o11c•6mo ago
I actually tried rewriting this in Python, but gave up since Python's startup latency is atrocious if you have even a few imports (and using a socket to a pre-existing server is fundamentally unable to preserve enough process context related to the terminal). Perl would probably be a better fit but it's $CURRENTYEAR and I've managed to avoid learning Perl every year so far, and I don't want to break my streak just for this.

The Bash code is not only fast but pretty easy to understand (other than perhaps the header, which I never have to change).

Fire-Dragon-DoL•6mo ago
Maybe try ruby, or you could use go (yeah, have to compile)
dataflow•6mo ago
PHP maybe? Or in limited cases, AWK? But I'd definitely learn Perl, it's a gem.
oguz-ismail•6mo ago
PHP needs to be installed, Perl is dead and AWK is more limited than Bash
ZYbCRq22HbJ2y7•6mo ago
> PHP needs to be installed

There are some ways around this:

https://github.com/crazywhalecc/static-php-cli

macintux•6mo ago
For what little it’s worth, Perl is very much not dead.
0xbadcafebee•6mo ago
Or go the other direction: stop trying to do fancy things and write simpler code that avoids errors.

  #!/bin/sh
  [ "${DEBUG:-0}" = "1" ] && set -x
  set -u
  foo="$( my-external-program | pipe1 | pipe2 | pipe3 )"
  if [ -z "$foo" ] ; then
      echo "Error: I didn't get any output; exiting!"
      exit 1
  fi
  echo "Well I got something back. Was it right?"
  if ! printf "%s\n" "$foo" | grep -q -E 'some-extended-regex' ; then
      echo "Error: '$foo' didn't match what I was looking for; exiting!"
      exit 1
  fi
  echo "Do the thing now..."
A lot of programs will either produce valid output as STDOUT, or if they encounter an error, not produce STDOUT. So for the most part you just need to 1) look for any STDOUT at all, and then 2) filter it for the specific output you're looking for. For anything else, just die with an error. If you need to find out why it didn't run, re-run with DEBUG=1.

Advanced diagnosis code won't make your program work better, but it will make it more complicated. Re-running with tracing enabled works just as well 99% of the time.

maccard•6mo ago
> A lot of programs will either produce valid output as STDOUT, or if they encounter an error not produce stdout

Lots of programs produce nothing in the success case and only print in the failure case.

o11c•6mo ago
Ah yes, the old "just write non-buggy code, or at least code whose bugs are deterministic".

My solution just silently sits in the background for unexpected, unpredictable bugs.

chubot•6mo ago
I think you should be able to get rid of the is-oil part, because set -E was implemented last year

    $ osh -c 'set -E; set -o |grep errtrace'
    set -o errtrace
I'd be interested in any bug reports if it doesn't behave the same way

(The Oils runtime supports FUNCNAME BASH_SOURCE and all that, but there is room for a much better introspection API. It actually has a JSON crash report with a shell stack dump, but it probably needs some polish.)

oguz-ismail•6mo ago
>I'd be interested in any bug reports

What's the point? You can't fix them anyway

jamesmiller5•6mo ago
They meant Oil(s) as in fixing bugs in the bash compatible replacement that they author for the OP's 'is-oil' check.
oguz-ismail•6mo ago
I know
bjackman•6mo ago
But trap doesn't "stack" (like e.g. defer in Go) so if you do this it's not available for other purposes like cleanup
teddyh•6mo ago
Yes. This also means that if you use a third-party shell library which uses “trap” internally (like shunit2), you can’t use “trap” in your own script at all.
gkfasdfasdf•6mo ago
not sure what you mean, you can have separate ERR and EXIT traps that run independently.
bjackman•6mo ago
Yeah but each only exists once. If you wanna clean up on ERR and also use that trap for debugging you need to implement some janky layer on top of the trap.

(FWIW my take away from issues like this is always: Bash is not a serious programming language. If you are running up against these limitations in real life it's time to switch language. The challenge is really in predicting when this will happen _before_ you write the big script!)

westurner•6mo ago
Setting PS4 gets decent error reports with `set -x` (and `set -x -v`; `help set`).

Here's an excerpt that shows how to set PS4 from a main() in a .env shell script for configuring devcontainer userspace:

  for arg in "${@}"; do
  case "$arg" in
  --debug)
      export __VERBOSE=1 ;
      #export PS4='+${LINENO}: ' ;
      #export PS4='+ #${BASH_SOURCE}:${LINENO}:${FUNCNAME[0]:+${FUNCNAME[0]}()}:$(date +%T)\n+ ' ;
      #export PS4='+ ${LINENO} ${FUNCNAME[0]:+${FUNCNAME[0]}()}: ' ;
      #export PS4='+ $(printf "%-4s" ${LINENO}) | '
      export PS4='+ $(printf "%-4s %-24s " ${LINENO} ${FUNCNAME[0]:+${FUNCNAME[0]}} )| '
      #export PS4='+ $(printf "%-4s %-${SHLVL}s %-24s" ${LINENO} "     " ${FUNCNAME[0]:+${FUNCNAME[0]}} )| '
      ;;
  --debug-color|--debug-colors)
      export __VERBOSE=1 ;
      # red=31
      export ANSI_FG_BLACK='\e[30m'
      #export MID_GRAY_256='\e[38;5;244m'    # Example: a medium gray
      export _CRESET='\e[0m'
      export _COLOR="${ANSI_FG_BLACK}"
      printf "${_COLOR}DEBUG: --debug-color: This text is ANSI gray${_CRESET}\n" >&2
      export PS4='+ $(printf "${_COLOR}%-4s %-24s%s |${_CRESET} " ${LINENO} "${FUNCNAME[0]:+${FUNCNAME[0]}}" )'
      ;;
   esac
   done
This, too:

  function error_handler {
    echo "Error occurred on line $(caller)" >&2
    awk 'NR>L-4 && NR<L+4 { printf "%-5d%3s%s\n",NR,(NR==L?">>>":""),$0 }' L=$1 $0 >&2
  }
  if (echo "${SHELL}" | grep "bash"); then
    trap 'error_handler $LINENO' ERR
  fi
kjellsbells•6mo ago
(I'm sure this is lovely Bash, but for all the people who rejected Perl for its modem line noise vibe...what do ya think of this?)

As an aside, I actually wonder if Bash's caller() was inspired by Perl's.

There is also Carp and friends, plus Data::Dumper when you not only need the stack trace but also the state of objects and data structures. Which is something that I don't think Bash can really do at all.

Grimeton•6mo ago
There are no objects in bash. There are indexed and associative arrays and both can be iterated over like so:

  for value in "${SOMEARRAY[@]}"; do
    echo "${value}"
  done
or with the help of the keys:

  for key in "${!SOMEARRAY[@]}"; do
    echo "key: ${key} - value: ${SOMEARRAY["${key}"]}"
  done
If you want to dump the data of any variable you can just use declare -p

  declare -p SOMEARRAY
and you get something like this:

  declare -a SOMEARRAY=([0]="a" [1]="b" [2]="c" [3]="d" [4]="e" [5]="f")
What you can do, if you have a set of variables and you want them to be "dumped", is this:

Let's "dump" all variables that start with "BASH":

  for k in "${!BASH@}"; do
    declare -p "${k}"
  done
Or one could do something like this:

  for k in "${!BASH@}"; do
    echo "${k}: ${!k}"
  done

But the declare option is much more reliable as you don't have to test for the variable's type.
westurner•6mo ago
Bash has associative arrays, but just POSIX shells like ash do not have associative arrays.

And, POSIX shell can only shift and unshift on the $@ array; so it would be necessary to implement hashmaps or associative arrays with shell string methods and/or eval.

westurner•6mo ago
Are you asking me to defend shell script syntax, or are you criticizing this except from a shell script?

The awk and printf are as obscure and unreadable as Perl, but still probably faster than just starting Perl.

Ironically, in terms of portability, it's probably more likely that awk and printf are installed than Python (or Perl). This application doesn't need Python in the (devcontainer) container, and nobody does sysadmin scripts with lua (which can't `export VARNAME` for outer shells) so shell scripting is justified though indeed arcane.

Getopt is hardly more understandable than a few loops through $@ with case statements.

I don't understand the relevance of other tools to "getting decent error reports in Bash"?

There are great logging (and TAP testing) libraries in Python, but that doesn't solve for debugging Bash?

There is at least one debugger for Bash scripts.

westurner•6mo ago
bashdb is a debugger for shell scripts: https://github.com/Trepan-Debuggers/bashdb

vscode-bash-debug is a frontend for bashdb: https://github.com/rogalmic/vscode-bash-debug

fragmede•6mo ago
Perl had numerous magic, one/two letter variables and copious regexp use, which is what gave it the line noise insult. Wtf is $@ and $_? After spending enough time breathing Perl you got a feel and could actually read it, but take a break and forget all the things, and it's back to being inscrutable. Meanwhile, the bash above isn't totally inscrutable. It's not python clear, and I don't know what SHLVL is without looking it up, but the rest is clear enough (awk with NR, isn't self explanatory, but unfortunately for me I've used too much awk).
9woc•6mo ago
beware of using this. any operations that returns non-zero exit status will cause immediately exit
mk12•6mo ago
For example `((n++))` where n is 0. I’m used to it enough that I usually remember to add `|| :` to the end of lines like this.