Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I advocate the following rules for when to write and when not to write a shell script.

# Write a shell script:

* Heavy lifting done by powerful tool (sort, grep, curl, git, sed, find, …)

* Script will glue diverse tools

* Workflow resembles a pipeline

* Steps can be interactively developed as shell commands

* Portability

* Avoid dependency hell

* One-off job

# Avoid shell scripting:

* Difficult to see the preceding patterns

* Hot loops

* Complex arithmetic / data structures / parameters / error handling

* Mostly binary data

* Large code body (> 500 LoC)

* Need a user interface

A need for associative arrays (implemented in Bash as via hashmaps) moves the task to the second category (avoid shell scripting).



I’ve been a sysadmin for nearly a decade, a frontend web designer for much longer (I still have a book on all the exciting changes in HTML4), and while I can very easily learn, compose, and use many markup and scripting languages, I have always struggled with full-on programming languages, and I’m not exactly sure why. Part of it, I think, is that most tutorials and online learning resources are focused on novices who don’t have any existing grasp on general programming concepts and syntax, but I’m already pretty deep into Bash. To the extent that I am sure I have crossed the thresholds you list, and used quite long and complex Bash scripts for tasks that would almost certainly be easier in Python. I’d love to find A Bash Scripter’s Guide To Python or something similar—an intermediate course that assumes that I already know about variables, operators, functions, Boolean expressions, et al. I have searched for this a few times, but it’s full of keywords that makes searching Google difficult.

So this has inspired me to Ask HN, I’m getting ready to post it with a reference to this discussion, but thought I’d start here: does anyone know of a good resource for learning Python (or Go, Perl…any good small project/scripting/solo hacking languages) that’s tailored for folks who already have a good foundation in shell scripting, markup, config/infra automation, build tools, etc.? I’m open to books, web-based tutorials, apps, or just good examples for studying.

I’m open to the notion that I simply haven’t put in the work, and powered through the doldrums of novice tutorials far enough to get to where the meaty stuff is. Worst case, I’m a big fan of taking courses at the local community college for my own edification, absent any specific degree program or professional certification. It would still necessitate a lot of remedial/redundant steps, but I can always help others through those chapters while filling in any of my own gaps. Day-to-day, I generally work alone, but I find such things are easier with others to help motivate and focus my efforts. Perhaps I have answered my own question, but even still, I appreciate any advice/recommendations folks might have.


One of the differences between "general programming" and the kinds of coding that you have done is the /approach/. I'm not sure if that's even the right word, but there's a different set of concerns that are important.

My guess is that you can easily learn the syntax and that you have the logical and analytical skills, but the part you have to learn is how to THINK about programming and how to DESIGN a program. If you have or haven't taking coding classes, I think reviewing topics like data structures, algorithms, encapsulation/object oriented programming, functional programming, etc. is the way to learn how to think about general programming. I don't think the language matters, but there might be resources about these topics in the language you're interested in.

An example of what you DON'T want is something like Effective Go (not just because it's out-of-date now): https://go.dev/doc/effective_go. This page can give you a really good base of information about what Go is, but I think you'll get much more bang for your buck with a resource that is more about the WHYs of programming rather than the WHATs.


This was honestly extremely helpful. I very much appreciate the advice. I think you’re probably correct in that my intuition and prior knowledge is not being particularly helpful with shifting my paradigmatic perspectives, and while I may not need the novice lessons to learn the vocabulary or practical concepts, I probably do need a better formal introduction to theory. I am largely self-taught, aside from 2-years in an electronics engineering program that included embedded programming, and lessons in logic and Boolean algebra, My bachelor’s was in media studies and film production. In my experience, practical knowledge can be obtained through hands-on exercise and observing others—but theory and philosophy usually requires a teacher (or maybe months of meditation in a cabin in the woods, but as much as I admire Henry David Thoreau as an author, he wasn’t a great software engineer), and it sounds like that’s what I am missing here. Community college classes it is.

Thanks again!


My search through existing Ask HN has shown that this, unsurprisingly, has been asked before by several people in other specific contexts (side note, Ask HN is such an incredibly useful resource, thanks to everyone who engages with these questions). I don’t want to add more noise, so I’m going to work through the existing answers before posting.

If anyone else is interested, this thread from 2020 is where I am starting, it seems to align with my own quest pretty well: https://news.ycombinator.com/item?id=22932794


> assumes that I already know about variables, operators, functions, Boolean expressions, et al.

Learning Go by Jon Bodner is a good choice. It seems to assume that Go is the reader's second (or tenth) language.


A couple things:

- Between using Bash's functions and breaking large scripts into multiple, separate scripts, one can keep things reasonably tidy. Also, functions and scripts can be combined in all the ways (e.g., piping and process substition) that other programs can.

- If I run into a case where Bash is a poor fit for a job, I ask myself, "Self, what program would make this easy to do in a shell script?" If I can respond with a good answer, I write that, then continue with the shell scripting. If not, I write in something else (what the kids would call a "proper" language).




Consider applying for YC's Winter 2026 batch! Applications are open till Nov 10

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: