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

Anything that already exists in my shell's history as a one-liner, but needs to be upgraded to a reusable script.

As far as I know, one liners are not possible in Python. As a matter of fact, I'm not aware of any popular tools that can even hold a candle to Perl's power at the command line. So, my options are:

1. Forget about one-liners. This is the option most people seem to take, and also by far the worst one. In my career I regularly saw my perfectly competent colleagues take minutes or hours to write throwaway scripts to do what I would do in seconds with a Perl one-liner.

2. Use Perl for one-liners, then rewrite the few that graduate to scripts in Python. This one isn't as obviously absurd as the first, but still seems like a rather large waste of time overall.

3. The obvious: paste your one-liner into a new file, add some newlines and whitespace and command-line options and whatever else.



That makes sense!

When I write one liners I tend to build them up in bash, and so when I want them to be reusable I do the same as your (3) but targeting bash. Then when they get at all complicated I rewrite in python.


The thing about bash is that it's much less powerful than perl, while at the same time being more prone to surprising, undesirable behavior and write-only code.

The worst of both worlds.


I agree that bash has a lot of flaws, but on the other hand it makes a much better shell than perl. I really value using the same language for ordinary interaction with my computer and automation of very simple tasks.




Consider applying for YC's Fall 2026 batch! Applications are open till July 27.

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

Search: