Live data from Hacker News

Ask HN: What to use instead of Bash / Sh for scripting?

news.ycombinator.com

81–90 of 106 posts

Re: Ask HN: What to use instead of Bash / Sh for scripting?

#81
> I don't know what version of Python I'm going to have on the system

You could have assumed Python 2.7 for 10 years or so.

Now you could safely assume Python 3 (find minimum version applicable for your case).

> installing dependencies is not fun,

Pure python dependencies are easy (e.g., pipenv). C extensions are not more difficult than corresponding dependencies for your bash script (likely via system packages).

> shelling out when needed is not pleasant, and the size of program always seemingly doubles.

Have you tried to use shell command for shell one-liners in Python? e.g., directly via `proc = subprocess.run(shell_pipeline, shell=True)` or dedicated libraries such as pyinvoke/fabric?

Re: Ask HN: What to use instead of Bash / Sh for scripting?

#82

Earlier quoted context omitted.

> If you want strong typing (are you scripting in the large?), then, almost by definition, no scripting language provides that. Powershell is basically strongly typed. > Can you be more specific than "fatigue"? That sounds like ennui I love my job, but bash makes me wanna hang myself. I can say the same about stored procedures. Its like going back to cobol days. Some people have strong tastes I guess.

I used “true” instead of “$True” in a power shell script. It didn’t error. It didn’t warn. It just evaluated to false. So doesn’t behave like a strongly typed language to me.

RTFM - if you don't specify type, it is infered.

    [bool] $x = "true"
    MetadataError: Cannot convert value "System.String" to type "System.Boolean". Boolean parameters accept only Boolean values and numbers, such as $True, $False, 1 or 0.

Re: Ask HN: What to use instead of Bash / Sh for scripting?

#83

Earlier quoted context omitted.

No, I said what I mean. Bash and its disasters like [ as executable and mega error prone and awkward language designed 50 years ago IS horror. Verbosity of powershell is optional, I don't use it. > consistency that comes with all Microsoft designed products. Oh, lets not troll here.

Disasters like powershell returning a 0 exit code even if there is an error? Its a pile of trash that doesn't add anything new other than a big shiny MS logo.

That is simply not true. RTFM - $ErrorLevel is for native apps $? is for cmdlets

Re: Ask HN: What to use instead of Bash / Sh for scripting?

#84

Earlier quoted context omitted.

How about pwsh -NoLogo -NoProfile ? > Measure-Command { pwsh -NoProfile -NoLogo exit } Days : 0 Hours : 0 Minutes : 0 Seconds : 0 Milliseconds : 254 BTW, Windows OS is often subject of Windows Defender and other AVs which are not present on Linux machines and their slowdown of the system is phenomenal.

Thanks for the suggestion. Adding these flags halves the startup time: $ time ./pwsh -NoProfile -NoLogo /dev/null real 0m0.456s user 0m0.388s sys 0m0.040s Much better, but I still wouldn't use this even as an interactive shell, as I open a few hundred terminal windows each day. There's no defender (or anything similar) on that other machine. It also has an SSD. With an older HDD powershell started in about 10-15 seco…

I open few hundred terminals each day. There is something seriously wrong with your machines. Pwsh is not a king of speed but 10-15 is local problem. Anything more then 2 seconds is a local problem. You can maybe get to 5 with lots of modules in your profile.

Re: Ask HN: What to use instead of Bash / Sh for scripting?

#85
post #48

Can you be more specific than "fatigue"? That sounds like ennui, in which case maybe consider a job switch instead of a language switch (not being sarcastic or intentionally mean). Bash plus all the Unix tools (awk, grep, sed, tsort, comm, the ones I don't know, etc.) have pretty long legs, in terms of functionality and the syntax is pretty understandable. They provide most of what Perl offers, apart from OO (-ish) a…

> If you want strong typing (are you scripting in the large?), then, almost by definition, no scripting language provides that. Powershell is basically strongly typed. > Can you be more specific than "fatigue"? That sounds like ennui I love my job, but bash makes me wanna hang myself. I can say the same about stored procedures. Its like going back to cobol days. Some people have strong tastes I guess.

Yeah, i forgot to add my thoughts on PowerShell. It's great for Windows and nothing else. Its power isn't syntax (which is a bit weird) but the fact that it interfaces with all the Windows APIs. I can't really imagine it on any other platform. If you're on Windows and nowhere else, PS is superior to bash. Have you been using bash on Windows? If so, why? Cross-Platform?

Re: Ask HN: What to use instead of Bash / Sh for scripting?

#86
post #85

Earlier quoted context omitted.

> If you want strong typing (are you scripting in the large?), then, almost by definition, no scripting language provides that. Powershell is basically strongly typed. > Can you be more specific than "fatigue"? That sounds like ennui I love my job, but bash makes me wanna hang myself. I can say the same about stored procedures. Its like going back to cobol days. Some people have strong tastes I guess.

Yeah, i forgot to add my thoughts on PowerShell. It's great for Windows and nothing else. Its power isn't syntax (which is a bit weird) but the fact that it interfaces with all the Windows APIs. I can't really imagine it on any other platform. If you're on Windows and nowhere else, PS is superior to bash. Have you been using bash on Windows? If so, why? Cross-Platform?

PS is superior to bash, period, no matter platform. You are talking about something else entirely, like added benefit of lots of Windows tools supporting PowerShell automation. While that is nice, the major appeal of pwsh for me is not the ecosystem but the paradigm and language - in bash, you always do something irrelevant to your current task as anything requires excessive boilerplate and all supportive utilities are reinventing stuff like parameter names and parsing, error handling, etc. Also, those utilities are sometimes different on other *nix platforms, so you can't even count on linux portability.

So yeah, PowerShell is huge on Windows and just awesome on Linux. You must also take into account that its only few years old in that space.

Re: Ask HN: What to use instead of Bash / Sh for scripting?

#87

For me: I use groovy. Reasoning behind it is that I am a software engineer specializing in JVM. On all the machines I work there is a JVM installed. Plus groovy is Java with extra stuff so it is a flavor of Java nothing new. And it does not require a compiler.

Same here! bonuses include:

- built in dependency manager so you can pull dependencies in just by putting @Grab at the top of your script

- interface with your actual code written in Java easily so you can easily have scripts that utilise your "real" code for business logic

- full java ecosystem of libraries trivially accessible

- genuine cross platform so none of the weird OS / architecture issues and conflicts you get with pre-installed python, etc etc

Re: Ask HN: What to use instead of Bash / Sh for scripting?

#88

Earlier quoted context omitted.

JavaScript as a shell replacement, what a time to be alive! I am familiar with and use quite a bit of js on the front end, but how is node for shelling out? This is something I find Python to be quite terrible at.

I wouldn't use it as an interactive prompt personally - it's a bit too verbose - though I did know someone in college who did that :) Calling shell commands is reasonably straightforward: const { exec} = require('child_process') const child = exec('ls', ['-lh', '/usr']) console.log('error', child.error) console.log('stdout ', child.stdout) console.log('stderr ', child.stderr) However, you can also get cool packages l…

It's far easier to do it on perl.

$output = `ls -lh /usr`;

I don't think I can remember all the boilerplate of using the wrong language for the job if I only happen to write that once a month or less.

Even PHP is easy.

$output = shell_exec('ls -lh /usr');

Re: Ask HN: What to use instead of Bash / Sh for scripting?

#89

Just use PowerShell. You can do so much in it without any dependency (jq is native in it and many other things). It is cross-platform so you can use your scripts anywhere. Don't use python or go or ruby or whatever as those are not scripting languages. IMO Bash is horror and should die already.

Powershell is a horror you mean, it's got the verbosity of objective c with the consistency that comes with all Microsoft designed products. Just use a proper scripting language.

Just looking at PS scripts makes my RSI flare up.

Re: Ask HN: What to use instead of Bash / Sh for scripting?

#90
post #47

Earlier quoted context omitted.

> its disasters like [ as executable Why is that a disaster? What problem has it caused you that wouldn't have happened if it wasn't an executable? [[ is a non-executable version of [. Does that solve your problem?

I don't have a problem - I don't use bash unless its few lines or absolute must. Its disaster because launching process to achieve simple math expression is just ridiculous, besides being slow and besides having to terminate it with ;. Its wrong on so many levels I don't even know where to start, they must have been smoking some nasty things back in time.

> launching process to achieve simple math expression is just ridiculous

That's why you don't do that. $(( math goes here ))

Post reply on HN