frontpage.
newsnewestaskshowjobs

Made with ♥ by @iamnishanth

Open Source @Github

Open in hackernews

Moreshell tricks: first class lists, jq, and the es shell

https://alurm.github.io/blog/2025-08-07-first-class-lists-in-shells.html
41•alurm•2d ago

Comments

jeffrallen•2d ago
I review shell scripts from beginner ops people. I would not approve any of this stuff. Once you need this complexity in shell, you need other things you should be getting from the language's stdlib. So I'd ask them to switch to Python or Go.

Do not fall into the trap of big complex shell scripts.

zhouzhao•2d ago
>Do not fall into the trap of big complex shell scripts

This so much.

SoftTalker•2d ago
There's a point where what you say is true but I would not view using 'jq' to tease a list out of some JSON data to be it. Isn't that what your python or go code is going to do? All jq is is a packaged set of calls to stdlib stuff.

Systems admins are generally not Python or Go experts. And those are two dependencies which may not be available anyway (or will require installation, and maintenancee, may introduce new vulns, etc.). You could say the same about 'jq' though.

calmbonsai•2d ago
I'll go further.

Shell is great for personal or local-group/team automation, but outside of a bootstrap, it should _never_ be used for anything in deployed production.

The 3 main issues are hidden deps, error handling, and performance.

floydnoel•2d ago
Overall I agree, but I think developers usually err the other way, where they are afraid of running any shell commands outside of invoking their developer tools.

I really enjoyed this article because I found it refreshing- it felt like it was intended for hackers. I love to learn more about different shells and functionality vs yet another unicorn's latest product announcement.

delta_p_delta_x•2d ago
I was about to comment with my usual 'why not PowerShell', but it seems the author acknowledges this anyway at the end:

> I’ll quote Rich’s sh (POSIX shell) tricks to end this:

> I am a strong believer that Bourne-derived languages are extremely bad, on the same order of badness as Perl, for programming, and consider programming sh for any purpose other than as a super-portable, lowest-common-denominator platform for build or bootstrap scripts and the like, as an extremely misguided endeavor

alurm•2d ago
Yeah, PowerShell and nushell are pretty cool, I hope they gain more adoption.
stouset•2d ago
I keep intending to give nushell a serious try, but I'm too set in my ways :(
packetlost•2d ago
This is why I use Plan9's rc shell for a lot of my scripting needs. It's dramatically nicer to write but even more nice to read.
its-summertime•2d ago
with bash namerefs, having a function like

    split-on-ddash outputa outputb a b c -- x y z
    for x in "${outputa[@]}"; do # ...
becomes feasible. Of course, don't do it.
alurm•2d ago
Sure.

I have tried Bash namerefs. I found them to be kinda awkward, since you need to name them uniquely. So, you have to pretend that they are global variables, even though they are declared inside a function, which makes their usage verbose.

Here, this could look like:

  split_by_double_dash() {
    declare -n split_by_double_dash_before=$1
    declare -n split_by_double_dash_after=$2
    
    split_by_double_dash_before=()
    split_by_double_dash_after=()

    ...
  }
chubot•2d ago
let’s implement split-by-double-dash, a function (or a program) that would return two lists: args that come before -- and ones that come after.

split-by-double-dash a b c -- d e f should return the lists [a, b, c] and [d, e, f]

FWIW in YSH (https://oils.pub/ysh.html), you can do this in a style that's like Python and JavaScript, but you can also combine it with shell idioms.

First create it and pretty print it:

    ysh-0.34$ var li = :| a b c -- d e f |  # shell word style, ['a', 'b'] style is also accepted

    ysh-0.34$ = li  # pretty print with =
    (List)  ['a', 'b', 'c', '--', 'd', 'e', 'f']
Then test out the indexOf() method on strings:

    ysh-0.34$ = li.indexOf('--')
    (Int)   3
Then write the function:

    ysh-0.34$ func splitBy(li) {
            >   var i = li.indexOf('--')
            >   assert [i !== -1]
            >   return ( [li[ : i], li[i+1 : ]] )  # same slicing as Python
            > }
Call it and unpack it

    ysh-0.34$ var front, back = splitBy(li)

    ysh-0.34$ = front
    (List)  ['a', 'b', 'c']
Use it in shell argv, with @myarray as splicing:

    ysh-0.34$ write -- @back
    d
    e
    f
alurm•2d ago
YSH looks very nice here, thanks. I thought to mention YSH, but have no experience with it, so I hoped you would comment.

(I guess we're duplicating threads at this point :D)

kjellsbells•2d ago
I know Perl gets no love here, and for good reason sometimes, but I have a hard time believing that code full of syntactical characters like

  if .["found"] then
    . | .after += [$arg]
  elif $arg == "--" then
    . | .found = true
  else
    . | .before += [$arg]
  end
or

  for (i = $indicies) if { ~ $*($i) -- } {
      before = <= {
  ...
...is more readable and maintainable than:

  my ($before, $after) = split /\s*--\s*/, $input;
  my @list1 = split ' ', $before;
  ...

The Most Nihilistic Conflict on Earth

https://www.theatlantic.com/magazine/archive/2025/09/sudan-civil-war-humanitarian-crisis/683563/
1•YeGoblynQueenne•5m ago•1 comments

Show HN: I'm trying to quit vape and hoping someone could join me

https://www.iquitvape.com/
1•jayqinohboi•9m ago•0 comments

What Declarative Languages Are

https://semantic-domain.blogspot.com/2013/07/what-declarative-languages-are.html
1•fanf2•15m ago•0 comments

I cancelled my Chat GPT subscription today

1•dontlike2chat•17m ago•0 comments

Onion: Stack Language Compiled to Lua

https://github.com/yumaikas/onion
2•Bogdanp•23m ago•0 comments

A Fully Automatic Morse Code Teaching Machine (1977)

https://c2.com/morse/
1•austinallegro•27m ago•0 comments

'It's missing something': AGI, superintelligence and a race for the future

https://www.theguardian.com/technology/2025/aug/09/its-missing-something-agi-superintelligence-and-a-race-for-the-future
1•nhojb•27m ago•0 comments

Workers whose jobs AI can do less likely than other workers to be unemployed

https://eig.org/ai-and-jobs-the-final-word/
1•JumpCrisscross•27m ago•0 comments

Hospital Shift Scheduling with OR-Tools

https://barkeywolf.consulting/posts/hospital-scheduling/
1•jjhbarkeywolf•30m ago•0 comments

Show HN: The "Firebase" for MCP Servers – Build, test, and deploy MCP servers

https://www.contexaai.com/
1•rupesh_raj29•30m ago•0 comments

Ask HN: Which Do you know any open source games?

1•Forgret•35m ago•1 comments

The new era of house music

https://open.spotify.com/playlist/2sCu2R0XnUTw9na0ofT4vb
1•playlsd•36m ago•0 comments

Logarithmic mean energy optimization a metaheuristic algorithm

https://www.nature.com/articles/s41598-025-00594-2
1•bryanrasmussen•38m ago•1 comments

Money Habits That Separate Successful Traders from the Rest

https://propfirmfx.com/
1•malavika_manoj•40m ago•1 comments

Systemic Racism and Memetics

https://medium.com/luminasticity/on-systemic-racism-f708ac2efe51
1•bryanrasmussen•40m ago•0 comments

Spent $510 on cursor in the last 30d – AMA

1•xucian•41m ago•0 comments

Globe TV: Free Live TV Worldwide

https://globetv.app/
1•thunderbong•41m ago•0 comments

Why Deep Learning Works Unreasonably Well

https://www.youtube.com/watch?v=qx7hirqgfuU
1•phildawes•1h ago•0 comments

CMakeDependencyDiagram – Interactive target dependency visualization for CMake

https://github.com/renn0xtek9/CMakeDependencyDiagram
1•renn0xtek9•1h ago•1 comments

Time to Talk Numbers

https://hugston.com/articles/Time_to_talk_numbers
1•trilogic•1h ago•1 comments

Who use and how are use the hand scan data?

1•aurelien•1h ago•0 comments

Why Paying for Spotify Mostly Pays Taylor Swift

https://mertbulan.com/2025/08/10/why-paying-for-spotify-mostly-pays-taylor-swift/
3•mertbio•1h ago•1 comments

Culture Game Over

https://web.archive.org/web/20171018143123/https://www.numair.com/culture/game-over
1•kwie•1h ago•1 comments

We're building "klarna" but for your annual software subscriptions

https://www.annualize.co/
2•bfayyumii•1h ago•2 comments

We're building "klarna" but for your annual software subscriptions

1•bfayyumii•1h ago•0 comments

Show HN: AI Coloring Pages Generator

https://aicoloringpages.app/
3•tomstig•1h ago•1 comments

Self-hosted open-source multi-user multi-platform secret management

http://day-to-day-stuff.blogspot.com/2025/08/self-hosted-open-source-multi-user.html
2•erikvanoosten•1h ago•0 comments

CUDA C++ Best Practices Guide [pdf]

https://docs.nvidia.com/cuda/pdf/CUDA_C_Best_Practices_Guide.pdf
2•throwawaybutwhy•1h ago•1 comments

'It's a Mess': A Brain-Bending Trip to Quantum Theory's 100th Birthday Party

https://www.quantamagazine.org/its-a-mess-a-brain-bending-trip-to-quantum-theorys-100th-birthday-party-20250808/
2•nsoonhui•1h ago•0 comments

Cloudflare vs. Perplexity:Why AI Scraping Without Paying Is Digital Theft [video]

https://www.youtube.com/watch?v=qehRsBYawkY
1•real-hacker•1h ago•1 comments