frontpage.
newsnewestaskshowjobs

Made with ♥ by @iamnishanth

Open Source @Github

Chemical process produces critical battery metals with no waste

https://spectrum.ieee.org/nmc-battery-aspiring-materials
45•stubish•2h ago•3 comments

Fast and cheap bulk storage: using LVM to cache HDDs on SSDs

https://quantum5.ca/2025/05/11/fast-cheap-bulk-storage-using-lvm-to-cache-hdds-on-ssds/
50•todsacerdoti•3h ago•11 comments

Smallest particulate matter sensor revolutionizes air quality measurement

https://www.bosch-sensortec.com/news/worlds-smallest-particulate-matter-sensor-bmv080.html
27•Liftyee•3h ago•3 comments

Resizable structs in Zig

https://tristanpemble.com/resizable-structs-in-zig/
109•rvrb•9h ago•48 comments

A low power 1U Raspberry Pi cluster server for inexpensive colocation

https://github.com/pawl/raspberry-pi-1u-server
16•LorenDB•3d ago•6 comments

Show HN: QuickTunes: Apple Music player for Mac with iPod vibes

https://furnacecreek.org/quicktunes/
70•albertru90•7h ago•18 comments

How we rooted Copilot

https://research.eye.security/how-we-rooted-copilot/
289•uponasmile•14h ago•110 comments

Purple Earth hypothesis

https://en.wikipedia.org/wiki/Purple_Earth_hypothesis
211•colinprince•3d ago•58 comments

Low cost mmWave 60GHz radar sensor for advanced sensing

https://www.infineon.com/part/BGT60TR13C
58•teleforce•3d ago•22 comments

Personal aviation is about to get interesting (2023)

https://www.elidourado.com/p/personal-aviation
81•JumpCrisscross•7h ago•80 comments

Rust running on every GPU

https://rust-gpu.github.io/blog/2025/07/25/rust-on-every-gpu/
523•littlestymaar•20h ago•176 comments

Paul Dirac and the religion of mathematical beauty (2011) [video]

https://www.youtube.com/watch?v=jPwo1XsKKXg
55•magnifique•8h ago•4 comments

16colo.rs: ANSI/ASCII art archive

https://16colo.rs/
20•debo_•3d ago•4 comments

Coronary artery calcium testing can reveal plaque in arteries, but is underused

https://www.nytimes.com/2025/07/26/health/coronary-artery-calcium-heart.html
67•brandonb•9h ago•57 comments

What went wrong for Yahoo

https://dfarq.homeip.net/what-went-wrong-for-yahoo/
155•giuliomagnifico•12h ago•148 comments

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

https://utcc.utoronto.ca/~cks/space/blog/programming/BashGoodSetEReports
101•zdw•3d ago•30 comments

The natural diamond industry is getting rocked. Thank the lab-grown variety

https://www.cbc.ca/news/business/lab-grown-diamonds-1.7592336
183•geox•18h ago•224 comments

Teach Yourself Programming in Ten Years (1998)

https://norvig.com/21-days.html
70•smartmic•9h ago•24 comments

Torqued Accelerator Using Radiation from the Sun (Tars) for Interstellar Payload

https://arxiv.org/abs/2507.17615
47•virgildotcodes•8h ago•4 comments

Tinyio: A tiny (~200 line) event loop for Python

https://github.com/patrick-kidger/tinyio
66•tehnub•4d ago•14 comments

Where are vacation homes located in the US?

https://www.construction-physics.com/p/where-are-vacation-homes-located
86•rufus_foreman•12h ago•69 comments

Arvo Pärt at 90

https://www.theguardian.com/music/2025/jul/24/the-god-of-small-things-celebrating-arvo-part-at-90
66•merrier•9h ago•19 comments

Shallow water is dangerous too

https://www.jefftk.com/p/shallow-water-is-dangerous-too
109•surprisetalk•3d ago•65 comments

Janet: Lightweight, Expressive, Modern Lisp

https://janet-lang.org
18•veqq•5h ago•2 comments

Test Results for AMD Zen 5

https://www.agner.org/forum/viewtopic.php?t=287&start=10
220•matt_d•12h ago•42 comments

Large ancient Hawaiian petroglyphs uncovered by waves on Oahu

https://www.sfgate.com/hawaii/article/hawaii-petroglyphs-uncovered-20780579.php
79•c420•4d ago•23 comments

Asyncio: A library with too many sharp corners

https://sailor.li/asyncio
84•chubot•7h ago•67 comments

Millet mystery: A staple crop failed to take root in ancient Japanese kitchens

https://phys.org/news/2025-07-millet-mystery-staple-crop-root.html
25•PaulHoule•3d ago•9 comments

Open Sauce is a confoundingly brilliant Bay Area event

https://www.jeffgeerling.com/blog/2025/open-sauce-confoundingly-brilliant-bay-area-event
329•rbanffy•3d ago•186 comments

Font-size-adjust Is Useful

https://matklad.github.io/2025/07/16/font-size-adjust.html
164•Bogdanp•3d ago•51 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
101•zdw•3d ago

Comments

newAccount2025•9h ago
Why don’t all shells just do this?
inetknght•9h 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•8h 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•8h 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•5h 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•4h ago
Looks slick. Works on older shells too
imcritic•8h ago
That's a pitfall №60

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

larkost•7h 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.

eikenberry•7h ago
What about for `/bin/sh`, i.e. posix compliant shells like dash?
koolba•9h ago
Automatically leaking the line number and command, even to stderr is not a sane default.
forrestthewoods•6h ago
Because shells weren’t supposed to be doing complex logic. People use shells to do way way way more than they should.
Grimeton•9h 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•5h ago
or even use caller to print a full backtrace: https://news.ycombinator.com/item?id=44636927
o11c•9h 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•8h 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•7h 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•7h ago
Maybe try ruby, or you could use go (yeah, have to compile)
dataflow•4h ago
PHP maybe? Or in limited cases, AWK? But I'd definitely learn Perl, it's a gem.
oguz-ismail•4h ago
PHP needs to be installed, Perl is dead and AWK is more limited than Bash
ZYbCRq22HbJ2y7•4h ago
> PHP needs to be installed

There are some ways around this:

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

macintux•2h ago
For what little it’s worth, Perl is very much not dead.
0xbadcafebee•1h 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.

chubot•7h 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•4h ago
>I'd be interested in any bug reports

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

bjackman•7h 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•7h 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•5h ago
not sure what you mean, you can have separate ERR and EXIT traps that run independently.
westurner•6h 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•3h 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•2h 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.