News for hackers. Stuff that matters.
Re:Safe ways to do things in bash by emmelaich on Tuesday May 15, 2018 @03:41AM (#17072294)
I probably have a similar history but I've come to the belief that you should not use Bash if you're doing anything fancy or long (>10 lines).

Just use Perl, Python or Ruby. One or all of them is installed on every machine you are likely to use.

Re:Safe ways to do things in bash by davedx on Tuesday May 15, 2018 @04:14AM (#17072412)
Yes, but which one, and which version? This is especially painful with Python ;)
Re:Safe ways to do things in bash by vinceguidry on Tuesday May 15, 2018 @09:34AM (#17073773)
Use Ruby. It doesn't change much from version to version, thank God. I curse python every time I have to install a package. Nothing Just Works.

If you install just one gem, bundler, you can get dependency management in a one-file script. Checkout Bundler Inline:

https://github.com/bundler/bundler/blob/master/lib/bundler/i...

Re:Safe ways to do things in bash by h1d on Tuesday May 15, 2018 @04:28AM (#17072482)
What's painful about Python but not so for others? Writing anything complicated in bash/zsh is painful enough I wouldn't even think about it.
Re:Safe ways to do things in bash by Groxx on Tuesday May 15, 2018 @04:37PM (#17077659)
2 vs 3 is not a small change. and tools for helping you do things (like a 3+2 compatibility lib) get installed with pip... which is horrifyingly fragile. `pip install your-lib` -> you have no idea if you have the dependencies you require, because pip doesn't behave rationally. it often Just Works™, but when it doesn't there's no help and a massive minefield of potential problems.
Re:Safe ways to do things in bash by CJefferson on Tuesday May 15, 2018 @07:46AM (#17073243)
I currently find some users have python2, some have python3, some both. It's fine in a controlled environment, or if your users are Devs, but a pain with normal users who I just want to send a script to.
Re:Safe ways to do things in bash by mncolinlee on Tuesday May 15, 2018 @12:32PM (#17075203)
KotlinScript is yet another option that handles that worry nicely.

https://github.com/holgerbrandl/kscript

Re:Safe ways to do things in bash by yAnonymous on Tuesday May 15, 2018 @06:36AM (#17072954)
Is there an easy way to run shell commands in Python, like backticks in PERL, Ruby or even PHP?

I'd really like to use Python more often, but most of the time it only complicates things with those verbose syscalls.

Re:Safe ways to do things in bash by passwd on Tuesday May 15, 2018 @10:38AM (#17074215)
IPython. Seems to work for simple stuff like `ls blah`, but I'm not aware how far this stretches, and is probably not super safe to use.

EDIT: Seems I've only tried too basic things - it works thanks to %automagic, and seemingly %man is a thing. Other option is to use %%sh or %%bash, but that's a bit verbose.

Re:Safe ways to do things in bash by monort on Tuesday May 15, 2018 @07:08AM (#17073085)
Check out python sh: https://github.com/amoffat/sh
Re:Safe ways to do things in bash by yAnonymous on Tuesday May 15, 2018 @09:02AM (#17073585)
>sh.ls("-l", "/tmp", color="never")

Nope. I really need to be able to test commands on the terminal and then copy/paste them without any modifications. I won't even try to get used to that stupid syntax.

Re:Safe ways to do things in bash by neillyons on Tuesday May 15, 2018 @06:57AM (#17073041)
Unfortunately not. I have used Ruby a little bit and that is really nice feature.
Re:Safe ways to do things in bash by rcxdude on Tuesday May 15, 2018 @11:42AM (#17074807)
part of the complication is due to actually having the proper data seperation that you need to jump through hoops to get in bash. If you go with backtick style calls you lose a lot of that.
Re:Safe ways to do things in bash by sxv on Tuesday May 15, 2018 @02:08PM (#17076182)
Re:Safe ways to do things in bash by freedomben on Tuesday May 15, 2018 @05:38PM (#17078095)
Except for perl, python and ruby are rarely on container images and AMIs I interact with unless they are needed for the application itself to minimize attack surfaces and vectors. Perl is installed sometimes due to dependent packages that themselves depend on perl, but that's becoming much less true as time goes on. With Docker it's also very easy to keep your image super minimal. Most of the time we don't even have bash installed (just sh).