News for hackers. Stuff that matters.
Re:Writing Safe Shell Scripts (2019) by sillysaurusx on Saturday February 01, 2020 @03:08PM (#22212892)
Ok, go ahead and port all 200 of these scripts to Python please: https://github.com/shawwn/scrap

PR's welcome. ;)

Python makes sense for scripts that need good argument parsing, or complicated intermediate input processing. But it's pretty annoying to get a shell pipeline working in Python. `foo | bar | baz` is about 15 characters in bash.

Here's an example. I use `llbranch` all the time: https://github.com/shawwn/scrap/blob/master/llbranch

It lists all branches in a project. It's nicely colorized. What would the equivalent Python be? Who knows, but it'd be much longer.

Re:Writing Safe Shell Scripts (2019) by ddebernardy on Saturday February 01, 2020 @03:34PM (#22213058)
Correct me if my first impression was incorrect, but scanning through your scripts they all seemed like sub-kilobyte one-liners. Which, yeah, just use Shell for those and you'll be fine.

To my mind, the parent post was referring to lengthier, more complicated scripts. Speaking as one who wrote and routinely maintained such scripts at one point, I cannot agree more with the sentiment that most if not all of them could and should have been written in Python or Ruby or some other scripting language instead.

Re:Writing Safe Shell Scripts (2019) by kohtatsu on Saturday February 01, 2020 @03:17PM (#22212965)
Cool repo, but the example is lame because a shell, or a git alias would do just fine.

A shell script that consists of a one-line exec isn't what people concerned about.

FWIW I'm a 99.9% POSIX masochist (probably closer to 4N)

Re:Writing Safe Shell Scripts (2019) by kohtatsu on Saturday February 01, 2020 @03:21PM (#22212988)
Looks like a lot of your scripts couldbe aliases, I store mine in ~/.aliases, and slightly more complicated things (e.g. take arguments) in ~/.functions, and source both those files from bashrc.

I have maybe 3 standalone shell scripts in my PATH, despite writing thousands of lines of shell.

Re:Writing Safe Shell Scripts (2019) by mfontani on Saturday February 01, 2020 @05:48PM (#22213754)
I've moved from aliases to scripts as I can't seem to have found the (if any exists...) way to ensure aliases can be used from within vim's ":!..." or ":'<,'>!...", and as I often find myself wanting to either execute something while I'm amending code, or wanting to filter text with a purpose-built command, I end up writing (sometimes very short!) shell scripts.
Re:Writing Safe Shell Scripts (2019) by ben509 on Saturday February 01, 2020 @03:39PM (#22213082)
I had a mess of shell functions. It is nice that they run more quickly, but I don't have any shell commands that need to run that often.

What moved me to putting them in a bin directory was that it's just easier to edit a standalone script.

Re:Writing Safe Shell Scripts (2019) by kohtatsu on Saturday February 01, 2020 @04:24PM (#22213337)
Write a shell script to concat them into a single file to source ;)