News for hackers. Stuff that matters.
Re:When Bash scripts bite by arjie on Friday May 12, 2017 @05:27AM (#14322507)
People always recommend Perl over a shell script but I've never seen a situation where it makes sense. Having written very little Perl, it seems like its only strength is that it's present everywhere and has a large library.

Language-wise, Python is far superior and has a large ecosystem and these days it has ubiquity too.

I'd be interested in the argument for Perl over shell scripts that does not apply to just writing the program in a modern language.

Re:When Bash scripts bite by kagamine on Friday May 12, 2017 @05:48AM (#14322597)
the problem with Python where I work is that developers are openly hostile toward it. We're predominantly .NET with just a couple of products running on Linux servers. I'm not a .net guy despite the pressure, and have been teaching myself python in my own time, but the the rest of the staff including management are never going to look for Python as a skill when hiring. EVER. But of course 2.7 is sitting there on the CentOS servers never used, while bash scripted cron jobs run amok and frequently fail (because they were written by the wrong people imo).

I would love to see Python utilized, and maybe with VSCode and MS integrating open source into the .NET world it will eventually come to enterprise (where I work).

Re:When Bash scripts bite by therealmarv on Friday May 12, 2017 @05:55AM (#14322628)
It's already there in the big Visual Studio: https://www.visualstudio.com/vs/python/

And it's a dream in VSCode + the most popular python extension https://github.com/DonJayamanne/pythonVSCode

Re:When Bash scripts bite by kagamine on Friday May 12, 2017 @06:32AM (#14322780)
it's not about what MS put in VS and VSCode, it's about changing the minds of .NET developers who used are to C# syntax/grammar and hate Python because it doesn't fit their world-view. "Already in VS" is meaningless in a .NET enterprise company.
Re:When Bash scripts bite by therealmarv on Friday May 12, 2017 @06:46AM (#14322834)
I feel sorry for you. Fanatism towards any language/eco-system, no matter if .net, Java, Ruby, Python (also have seen the same with Python developers) is something I really don't like.
Re:When Bash scripts bite by therealmarv on Friday May 12, 2017 @05:36AM (#14322543)
Have you ever done string manipulation (also RegEx) over many files in Perl? I think it's in this regard superior than anything else, even python when looking at syntax.
Re:When Bash scripts bite by arjie on Friday May 12, 2017 @07:00AM (#14322881)
I have not. I usually use `sed` in such instances but admitting the superiority of Perl in such instances surely this is insufficient on its own to use Perl? Seems like a rare use-case and if that script grows large then Python has superior language features but if the script stays small, then a Bash script with `sed` will do just as well.
Re:When Bash scripts bite by Outpox on Friday May 12, 2017 @05:54AM (#14322625)
For someone who hasn't done any Perl yet and only little Python could you explain why?
Re:When Bash scripts bite by mfontani on Friday May 12, 2017 @06:19AM (#14322729)
For the specific thing the OP mentioned, this:

    $ perl -pi -e 's/MY_NAME/Marco/g' ./*.txt
... would go through all "*.txt" files in the directory, and globally replace the token "MY_NAME" with "Marco".

Great for a {poor man's,simple and easy to understand} basic template system to be used inside a bash script ;)

Re:When Bash scripts bite by JetSpiegel on Friday May 12, 2017 @07:47AM (#14323115)
Overkill. Just use:

    $ sed -i 's,MY_NAME,Marco,g' *.txt
Re:When Bash scripts bite by therealmarv on Friday May 12, 2017 @09:05AM (#14323617)
nope. I've dealt recently with some big DB files (I think GB size) and regex doing the same. sed is a lot slower than perl for this kind of task.
Re:When Bash scripts bite by jstimpfle on Friday May 12, 2017 @09:55AM (#14323953)
I don't know how sed and perl compare, but I know these things:

Use a C local (e.g. LANG=C or LC_ALL=C) for dramatic speed up of tools like grep/sort and probably also sed. If you don't do that, usually the UTF-8 parser kicks in, which is a lot slower.

Perl is actually well known to have a non-optimal regex implementation: https://swtch.com/~rsc/regexp/regexp1.html That said, I don't know how fast it is (what optimizations it has) at simple string substitutions.