5 ms·
Ask HN: What's your favorite scripting language?
For programs that are too complex for bash, but still need to use shell commands and process command line input. Props if it's included by default in major Linux distros.
- cjbprime 7y agoPython's the only serious candidate that fits those requirements. Node is popular recently but I don't think e.g. Ubuntu installs it by default, or even has a modern version in its apt repos.
- jasonhansel 7y agoIMHO Python makes it too hard to run shell commands & perform other Unix magic. Personally, I like perl5, perl6, and tcl in these respects, but those languages aren't especially popular now. EDIT: also virtualenvs make my head explode. I think node/npm is currently the best in terms of dependency management.
- kungtotte 7y agoImport a standard library module and write a single line of code is "too hard"?
- jasonhansel 7y agoYes. In perl 5 and shell, it's just magic backticks
- rsyring 7y agoSo...this is too hard? import subprocess subprocess.run(["ls", "-l"]) # or subprocess.run("exit 1", shell=True, check=True) Reference: https://docs.python.org/3/library/subprocess.html https://docs.python.org/3/library/subprocess.html
- blacksqr 7y agoTcl: exec ls -l
- tomthehero 7y agoIt's not hard, just too much noise. from subprocess import run run("ls -la".split()) This is what I do to reduce noise
- mindcrime 7y agoTry Groovy: $groovy -e ' println "ls -l /".execute().text' Without the "run the example on the command line" baggage, it reduces to: println "ls -l".execute().text assuming you just want to spit out the results. What's nice about this is that it's ultimately just syntactic sugar over the standard Java ProcessBuilder / Process mechanism, and it's relatively easy to support more advanced cases like defining your own input, output, and error streams for the underlying process, etc.
- PaulHoule 7y agoPython. I use it on Windows and on Linux and sometimes a Mac.
- thesuperbigfrog 7y agoPerl 5 is old, but reliable. Many people deride it as a write-only language or executable line noise, but you can write ugly code in any language. Perl 5 can be terse or verbose depending on your needs. It is not "one size fits all" like Python, it fits many different sizes depending on your needs (TIMTOWTDI). You also have tons of modules available via CPAN, so you can get a script done quickly. Don't get me wrong: I use Python too, but some systems only have Python 2 and Python's significant white space can be problematic at times. Perl is an old, reliable camel that you can trust to get you through your problem desert quickly, frequently before the Python caravan has started out.
- jasonhansel 7y agoI also like Perl, and it's common on Linux. My issue is that perl 5 is obsolete, and perl 6 isn't included in most distros.
- thesuperbigfrog 7y agoHow exactly is Perl 5 obsolete? Perl 5.30 just came out in May. So it is still actively being maintained and improved. Perl 5 is included by default in most Linux distros and there are Perl distributions available for all major operating systems and platforms. (See http://www.cpan.org/ports/index.html http://www.cpan.org/ports/index.html for the comprehensive list.) Obsolete != Trendy / popular
- jasonhansel 7y agoI just mean that it's not the latest version of perl (now that perl 6 exists).
- thesuperbigfrog 7y agoPerl 6 is also Perl, but Perl 5 was the glue of the Internet with millions of lines of Perl 5 code written and still in use. Perl 6 was a bit slow to start and has not seen wide adoption. With Python, Ruby, and now even Powershell as scripting competitors, people have more options and aren't choosing it as much. Perl 5 was an easy choice when it was practically a standard part of LAMP stacks via mod_perl in the Apache web server. Now there are so many backend web server choices you can pretty much use any major programming language. I don't think Perl 6 will displace Perl 5. Perl 5 may even out last Perl 6.
- childintime 7y agoThis question belongs to Randall Schwarz, author of Learning Perl and presenter of Floss Weekly. His default answer to this question, Perl, has changed a bit recently, and might surprise.
- thesuperbigfrog 7y agoWould you please provide a link to Randall's response? I know he has taken a liking to Dart / Flutter, but I have not seen / heard what he said.
- getdreambits 7y agoPython. You can do pretty much anything with it, yet it's easy to grok and become quickly productive in.
- nextos 7y agoI loved Ruby. For me it had most of the niceties Perl had, plus a much cleaner design. Sadly Rails outshined plain Ruby, except in Japan.
- joshstrange 7y agoThis won't be popular but... NodeJS. It's easy to grab input from the CLI, "shelling out" isn't really all that bad and often I want to do some "business logic" type stuff in code really quick and I know the toolset very well. It's much faster for me to do stuff in JS even if it might be slightly slower to execute. Execution time is rarely what I'm optimizing for in one-off scripts or even things I might run on a regular basis. My ability to understand the code and make changes is valued much higher for me.
- quickthrower2 7y agoI have a side project that is using JS (typescript fwiw) for a data pipeline, a server, browser code and a tool to set up elastic search. Using the same lingo throughout the app is cool and there is even some shared libraries across the stack.
- joshstrange 7y agoIs that project OS or on github? I’m just about in love with typescript and would love examples of the things you are talking about. I’ve been playing around with setting up an example project that uses TS and a couple of tools I use regularly so I can just use it as a starter.
- bradknowles 7y agoSo, a language where the average program has something like 1900 dependencies and sub-dependencies? Seriously?
- joshstrange 7y agoSee: It won’t be popular.. #LeftPad listen I get the negatives. I’m not on HN to argue with people who are too buy letting good be the enemy of great. I’ve got work to do and NodeJS lets me do that. If you want to hate or spread FUD then that’s on you, me? I’ve got better things to do.
- uhryks 7y agoWhat are you talking about? You don't need npm to run scripts and Node.js has a standard library.
- vorg 7y agoThe title should be "What's your favorite Linux scripting language?" Presumably you don't want to talk about Powershell (Windows), Javascript (Web), or Apache Groovy (JVM).
- wglb 7y agoOr, for good grief, REXX.
- mindcrime 7y ago> Or, for good grief, REXX. FWIW, Rexx is readily available on Linux. [prhodes@whiskey pdfs]$ dnf search rexx Last metadata expiration check: 0:29:48 ago on Sat 06 Jul 2019 10:50:28 PM EDT. ========================================================== Name & Summary Matched: rexx ========================================================== oorexx.x86_64 : Open Object Rexx oorexx.x86_64 : Open Object Rexx oorexx-libs.x86_64 : Libraries for ooRexx oorexx-libs.i686 : Libraries for ooRexx oorexx-libs.x86_64 : Libraries for ooRexx brexx.x86_64 : Classic Rexx Implementation oorexx-docs.x86_64 : Documentation for ooRexx oorexx-docs.x86_64 : Documentation for ooRexx rexx-imc.x86_64 : IMC's interpreter for the Rexx oorexx-devel.x86_64 : Header files and libraries for ooRexx oorexx-devel.i686 : Header files and libraries for ooRexx oorexx-devel.x86_64 : Header files and libraries for ooRexx
- indentit 7y agoPowerShell Core / 6 is cross platform...
- chmielewski 7y agoRedlang
- gulabjamyn 7y agoI've used it a bit. Care to elaborate. I mostly use ruby, but perl5 and python will do, too.
- chmielewski 7y agoIt’s so much fun! Red view is my favorite scripting language
- mindcrime 7y agoGroovy and/or Python depending on what I'm doing. If I want to do something where I know using some Java library that I'm already familiar with will help, I will definitely use Groovy.
- mindcrime 7y agoI especially like the .execute() method in Groovy. Just create a String that represents a valid command, call .execute() on it, and use the .text property to get the output. For example: $groovy -e ' println "ls /".execute().text'
- nanomonkey 7y agoJoker (Clojure syntax written in Go).
- im_down_w_otp 7y agoTo read: AppleScript To write: escript (part of Erlang)
- deleted 7y ago[deleted]
- semperdark 7y agoI really enjoy Wren (https://github.com/wren-lang/wren https://github.com/wren-lang/wren) and have used it for a few of my personal programs.
- uponcoffee 7y agoLua. I never really got behind importing a package for everything, so the lack luster package management/community doesn't bother me. The syntax is fairly clean (its a nice break from braces and semi colons everywhere), it's easy to extend, and it's perf under LuaJIT is hard to argue with.
- bradknowles 7y agoMy favorite scripting language is still bash.
- geocrasher 7y agoMost things I need to get done can be done in bash. I know it, I am comfortable using it, and everything I log into has it. So it's what I use. Python is great too of course, but I don't really know it- I haven't had a need. I tried learning Perl once but reverted back to Bash the first thing I needed to do something in a hurry. And, my IDE is also my interpreter. It's pretty hard to argue with. I can just take a one-liner and throw it in a file and now I can distribute it. It's that simple. I suppose if I could write Python one-liners (maybe you can, I don't know...) and it was as universally installed and configured, I'd use it- if I needed to. What it comes down to is this: My needs are simple, and if I can't do it in bash, then I'm probably going about it wrong.
- p1p 7y agoPython as it's default on Linux.
- roryrjb 7y agoMy favourite scripting language is POSIX shell. It is also my most used language in terms of different "projects" I write with it; most of these projects are very small and focused. I feel that shell programming is very misunderstood, this is conjectural of course, but people dismiss it out of hand and move on up to something like Python usually. I have some rules of thumb: if you need to use a hash data type then move on to something else; if your LOC starts getting big then probably move on; always use ShellCheck. Just like every language ever, it has some warts, and it has some features that make it less readable and maintainable, but POSIX shell above all others (to me) having less features actually makes it easy to avoid the pitfalls. Of course in general I don't write massively complicated programs in POSIX shell but that's not the point, but it can take you very far, you just have to wrap your mind around how to implement certain things compared to other languages. I think the time taken to do that, in the long run will pay off. Of course if figuring it out takes too long, then move on to something else. As for the something else Perl is a very good candidate and is influenced in certain ways by shell programming. It just makes things easier. To me Perl is as readable as Python. I say this as someone who uses Python and Node.js in the day job, so in terms of LOC they are my main used languages, it's just that POSIX shell and Perl are better suited to the tasks as stated by the question. Also they are more portable, as in, both seem to be already present on a lot of Unices (I have no idea about macOS which I never have to touch or really care about).
- _448 7y agoPike Language (https://pike.lysator.liu.se https://pike.lysator.liu.se)
- zmmmmm 7y agoPeople definitely shouldn't overlook Groovy for this kind of scripting. Especially if you are doing anything with the JVM it has the huge advantage of allowing you to easily integrate your actual application code into your scripts and call it directly, all while using a scripting language that is more powerful, versatile and cross-platform than other obvious options such as Python.
- jolmg 7y agoHaskell is pretty nice for scripting, too. It's very concise, and the strong static type system gives assurance that the code will probably work before even running it.