News for hackers. Stuff that matters.
Re:Why Create a New Unix Shell? by Macha on Wednesday January 31, 2018 @06:49PM (#16278639)
My personal threshold for upgrading from shell to Python is about "I need an if statement".
Re:Why Create a New Unix Shell? by jeremyjh on Wednesday January 31, 2018 @07:54PM (#16278945)
Yeah I've seen that Python code. Every other line is a call to os.system('...').
Re:Why Create a New Unix Shell? by sethrin on Thursday February 01, 2018 @01:34AM (#16279991)
You say that like it's a bad thing. Bash does not support niceties like typed variables, named parameters, or classes. Its conditional operator is an external program with a required last argument to make it look like sane syntax. Little things like interpolating variables, array access, or taking command line options are awkward and prone to failure. It doesn't have the insane syntactical issues that csh had, and POSIX is ubiquitous, but that's a pretty low bar and an inadequate justification for using a fundamentally limited language. Python could have a nicer syntax for invoking the system interpreter -- personally, I think that Ruby's backticks feel very Unixy -- but if there is a better interpreter on the system there is no reason not to use it. Even if half your code is calling out to the shell, you still have the benefits of typed variables, a nicer syntax, the ability to abstract code into classes, a variety of nice enumeration options, and all the other benefits of a "real" programming language.
Re:Why Create a New Unix Shell? by watersb on Thursday February 01, 2018 @05:38AM (#16280841)
declare -a myArray=("foo" "bar" "baz")

echo "${myArray[2]}"

Bash is weird.

Re:Why Create a New Unix Shell? by dsnuh on Thursday February 01, 2018 @01:45AM (#16280029)
I've had good luck with this module. Much nicer than using os.system() imo.

https://amoffat.github.io/sh/

Re:Why Create a New Unix Shell? by arghwhat on Thursday February 01, 2018 @04:40AM (#16280581)
never use os.system. os.system is a hack.

Subprocess is a bit verbose to use, though... A wrapper would be nice.

Re:Why Create a New Unix Shell? by dsnuh on Thursday February 08, 2018 @11:17PM (#16337855)
I wasn't recommending os.system() ever, OP used it in the example. Subprocess is better, as you said. I think the sh module is better than Subprocess as well.
Re:Why Create a New Unix Shell? by Rotareti on Thursday February 01, 2018 @05:39AM (#16280853)
Since python3.6 it's just subprocess.run(). The SP module was refactored. I hope that eliminates the need for all these annoying (IMHO) wrappers.
Re:Why Create a New Unix Shell? by arghwhat on Thursday February 01, 2018 @07:39AM (#16281416)
Ah, that's nice!

... unfortunately, I'm stuck with python2.4 or 2.6 on most machines my Python code has to run on. :/

Re:Why Create a New Unix Shell? by Sean1708 on Thursday February 01, 2018 @10:16AM (#16282374)
> I'm stuck with python2.4 or 2.6

Not even 2.7?! 2.6 hasn't had a security update since 2013[0], I dread to think how old 2.4 is.

[0]: https://www.python.org/download/releases/2.6.9/

Re:Why Create a New Unix Shell? by arghwhat on Thursday February 01, 2018 @10:44AM (#16282632)
Python2.4 is what RHEL/CentOS 5 has to work with... And the extended support for that bloody release lasts till 2021.

You can install a newer version, but our CentOS 5 machines are meant for compatibility tests, so modifying their setup is unacceptable.

Re:Why Create a New Unix Shell? by dsnuh on Thursday February 08, 2018 @11:21PM (#16337866)
Have you tried using the scl repos from RedHat/CentOS? I use it at work yo enable different versions of Python at a system level if I am unable to muck with it because of yum.

I believe they are available for CentOS 5.x?

Re:Why Create a New Unix Shell? by rendaw on Thursday February 01, 2018 @04:54AM (#16280623)
Every other line of my code is check_call. Could you expand on the issue you're observing?
Re:Why Create a New Unix Shell? by nickcw on Thursday February 01, 2018 @05:27AM (#16280781)
check_call for the win! I contributed check_call to the subprocess module for exactly that purpose - easier shell like scripting in python :-)