frontpage.
newsnewestaskshowjobs

Made with ♥ by @iamnishanth

Open Source @Github

Open in hackernews

Debugging Bash Like a Sire (2023)

https://blog.brujordet.no/post/bash/debugging_bash_like_a_sire/
51•gfalcao•3d ago

Comments

t43562•3d ago
I never thought of the idea of printing out a stack trace. A logging function is an example of such a good idea that is so obvious that I didn't think of it :-)

I use -e sometimes but I really dislike scripts that rely on it for all error handling instead of handling errors and logging them.

https://www.shellcheck.net/

^^ this tool has proven very useful for avoiding some of the most silly mistakes and making my scripts better. If you're maintaining scripts with other people then it is a great way of getting people to fix things without directly criticising them.

oneshtein•1h ago
You can use bash-modules if you like stack traces in bash.
mjd•4h ago
I've been writing scripts in Bourne shell since the 1980s and in Bash since whenever it came along, and I feel like the most important thing I've learned about it is: don't. Sure, it can be done, and even done well, but why? There are better languages.

Every time I write a shell script that grows to more than about 20 lines I curse myself for not having written it in Python. The longer I have waited before throwing it away and redoing it, the more I curse.

This article says nothing to change my mind. I could build logging and stack traces in Bash. I admire the author's ingenuity. But again, why?

orhmeh09•4h ago
Because it's better at the task than Python is.
hiAndrewQuinn•4h ago
It won't be surprising since I wrote [1], but I mostly write bash when I want to create complicated pipelines with fzf, and I don't want to write Go code to go the same thing.

[1]: https://andrew-quinn.me/fzf/

pdimitar•3h ago
You have my admirations for fzf, it helps me dozens of times every day. And I do understand that authors of such prominent tools will want to have tamed integrations with people's shells, makes perfect sense.

That being said, as a guy who does not have big prominent OSS tools under his belt, I am slowly but surely migrating away from shell scripts and changing them to short Golang programs. Already saved my sanity a few times.

Nothing against the first cohort of people who had to make computers work; they are heroes. But at one point the old things only impede and slow everyone else and it's time to move on.

jelder•5m ago
This is an excellent point about pipes. There seems to be no other language which lets you stitch together pipes like Bash does. It's incredibly powerful, and worth putting up with all of Bash's warts.

Thanks for fzf, by the way. Always one of the first things I install in a new environment.

kajkojednojajko•2h ago
> the most important thing I've learned about [bash] is: don't. Sure, it can be done, and even done well, but why? There are better languages.

This. Bash gives you all the tools to dig a hole and none to climb out. It's quick and easy to copy commands from your terminal to a file, and it beats not saving them at all.

Support for digging: once you have a shell script, adding one more line conditioned on some env var is more pragmatic than rewriting the script in another language. Apply mathematical induction to grow the script to 1000 lines. Split into multiple files when one becomes too large and repeat.

Missing support for climbing out: janky functions, no modules, user types, or tests; no debugger and no standard library. I've successfully refactored messy python code in the past, but with bash I've had no idea where to even start.

There is hope that LLMs can be used to convert shell scripts to other languages, because they can make the jump that experienced devs have learned to avoid: rewriting from scratch. What else do you do when refactoring in small steps is not feasible?

pdimitar•2h ago
> There is hope that LLMs can be used to convert shell scripts to other languages, because they can make the jump that experienced devs have learned to avoid: rewriting from scratch. What else do you do when refactoring in small steps is not feasible?

There were some languages shown in HN that compile to sh/bash (like oilshell[0]). I would think that's also a viable vector of attack but not sure how viable it actually is i.e. maintainers might have moved on for various reasons.

[0] https://github.com/oils-for-unix/oils

latexr•1h ago
As someone who has been writing shell scripts for a few decades (though not as long as you), I’d instead recommend “learn what your tools are appropriate for and use them that way”. There are plenty of cases where shell scripts are the right tool for the job.

I can’t even tell how many times I’ve seen multi-line Python scripts which could instead have been a shell one-liner. Shorter and faster.

I have also written shell scripts with hundreds of lines, used by thousands of people, which work just fine and would be more complicated and slower in other languages.

I firmly disagree with the all too pervasive blanket statement of “there are better languages”. It depends. It always does.

jeffrallen•29m ago
An excellent use case for AI coders today is, "change this she'll script that's gotten too big into python". :)
Y_Y•4h ago
I find that `bash -x` actially gives such a good trace that I rarely need anything else. Coupled with the ancient wisdom "bash for quick and dirty, once it gets too fancy switch to python", I use bash a lot and find it manages really well without external tools. Shoutouts to shellcheck though, for catching a lot of edge cases.
ygritte•32m ago
Yep, shellcheck + syntastic in vim makes for a great bash "IDE".
toolmantim•3h ago
Reminds me of Keith Pitt’s (Buildkite founder) latest streams: https://twitch.tv/magickeith/
chasil•2h ago
It is always helpful in recording if any bash behavior changes when it is not running in POSIX mode.

This is most common in Debian and Ubuntu, where ash is /bin/sh, and /bin/bash does not run in POSIX mode by default.

Some behavior of legacy bash of the '80s, prior to POSIX.2, can be surprising.

https://w3.pppl.gov/info/bash/Bash_POSIX_Mode.html

agumonkey•2h ago
I had zero idea bash exposed the stack this way.. i'm utterly stumped.
rook_line_sinkr•28m ago
Many commenters recommend shellcheck

For actually _testing_ the scripts or its functions, I recommend ShellSpec

https://github.com/shellspec

neves•17m ago
Nice article. Do you have any shell debugging tip not listed in the article?

“Dynamic Programming” is not referring to “computer programming”

https://www.vidarholen.net/contents/blog/?p=1172
234•r4um•3d ago•120 comments

The Daily Life of a Medieval King

https://www.medievalists.net/2025/07/medieval-king-daily-life/
126•diodorus•3d ago•66 comments

Perl Versioning Scheme and Gentoo

https://wiki.gentoo.org/wiki/Project:Perl/Version-Scheme
15•RGBCube•1d ago•8 comments

Staying cool without refrigerants: Next-generation Peltier cooling

https://news.samsung.com/global/interview-staying-cool-without-refrigerants-how-samsung-is-pioneering-next-generation-peltier-cooling
322•simonebrunozzi•15h ago•238 comments

Log by time, not by count

https://johnscolaro.xyz/blog/log-by-time-not-by-count
142•JohnScolaro•10h ago•44 comments

Show HN: X11 desktop widget that shows location of your network peers on a map

https://github.com/h2337/connmap
159•h2337•11h ago•65 comments

ESP32-Faikin: ESP32 based module to control Daikin aircon units

https://github.com/revk/ESP32-Faikin
74•todsacerdoti•8h ago•30 comments

Debugging Bash Like a Sire (2023)

https://blog.brujordet.no/post/bash/debugging_bash_like_a_sire/
52•gfalcao•3d ago•18 comments

XMLUI

https://blog.jonudell.net/2025/07/18/introducing-xmlui/
538•mpweiher•21h ago•284 comments

New colors without shooting lasers into your eyes

https://dynomight.net/colors/
445•zdw•3d ago•123 comments

Agents built from alloys

https://xbow.com/blog/alloy-agents/
128•summarity•11h ago•61 comments

The sumerian game early computer game

https://spillhistorie.no/2025/07/10/the-sumerian-game-the-ancestor-of-modern-city-builders/
22•christkv•2d ago•5 comments

Structuring Arrays with Algebraic Shapes [video]

https://www.youtube.com/watch?v=3Lbs0pJ_OHI
22•surprisetalk•2d ago•1 comments

Simulating hand-drawn motion with SVG filters

https://camillovisini.com/coding/simulating-hand-drawn-motion-with-svg-filters
231•camillovisini•4d ago•17 comments

Coding with LLMs in the summer of 2025 – an update

https://antirez.com/news/154
522•antirez•1d ago•358 comments

Hexanitrogen Energies

https://www.science.org/content/blog-post/hexanitrogen-energies
12•thomasjb•2d ago•3 comments

Super-resolution microscopes reveal new details of cells and disease

https://knowablemagazine.org/content/article/technology/2025/super-resolution-microscopes-reveal-new-details-cells
6•rbanffy•2d ago•0 comments

Stdio(3) change: FILE is now opaque

https://undeadly.org/cgi?action=article;sid=20250717103345
147•gslin•17h ago•70 comments

Using the Matrix Cores of AMD RDNA 4 architecture GPUs

https://gpuopen.com/learn/using_matrix_core_amd_rdna4/
62•ibobev•2d ago•3 comments

Show HN: Conductor, a Mac app that lets you run a bunch of Claude Codes at once

https://conductor.build/
191•Charlieholtz•3d ago•86 comments

How to handle people dismissing io_uring as insecure? (2024)

https://github.com/axboe/liburing/discussions/1047
86•nromiun•5h ago•82 comments

AI is killing the web – can anything save it?

https://www.economist.com/business/2025/07/14/ai-is-killing-the-web-can-anything-save-it
245•edward•1d ago•306 comments

Speeding up my ZSH shell

https://scottspence.com/posts/speeding-up-my-zsh-shell
195•saikatsg•19h ago•97 comments

Subreply – An open source text-only social network

https://github.com/lucianmarin/subreply
112•lcnmrn•17h ago•62 comments

What my mother didn’t talk about (2020)

https://www.buzzfeednews.com/article/karolinawaclawiak/what-my-mother-didnt-talk-about-karolina-waclawiak
67•NaOH•3d ago•29 comments

IPv6 Based Canvas

https://canvas.openbased.org/
68•tylermarques•13h ago•11 comments

SIOF (Scheme in One File) – A Minimal R7RS Scheme System

https://github.com/false-schemers/siof
52•gjvc•2d ago•5 comments

How slow motion became cinema’s dominant special effect

https://newrepublic.com/article/196262/slow-motion-became-cinema-dominant-special-effect-downtime
35•cainxinth•3d ago•22 comments

FFmpeg devs boast of another 100x leap thanks to handwritten assembly code

https://www.tomshardware.com/software/the-biggest-speedup-ive-seen-so-far-ffmpeg-devs-boast-of-another-100x-leap-thanks-to-handwritten-assembly-code
335•harambae•14h ago•96 comments

JOVE – Jonathan’s Own Version of Emacs

https://github.com/jonmacs/jove/
65•nanna•4d ago•41 comments