News for hackers. Stuff that matters.
Re:Writing Safe Shell Scripts (2019) by heavyset_go on Saturday February 01, 2020 @03:18PM (#22212967)
I've yet to find a programming language that makes I/O redirection, piping, and process substitution[1] as easy as Bash does. Process substitution is where the shell really shines, in my opinion.

Bash, and Bash-like shells, are literally everywhere. I have to be wary about what Python 3 features I use, and if there will even be a Python interpreter available. My OpenWRT router has a Bash shell, but I don't care to install and maintain other interpreters or runtimes on an embedded platform.

Even job management and parallelism are easier in Bash and GNU Parallel.

[1] https://www.tldp.org/LDP/abs/html/process-sub.html

Re:Writing Safe Shell Scripts (2019) by ilyash on Tuesday February 04, 2020 @04:29AM (#22233780)
> I've yet to find a programming language that makes I/O redirection, piping, and process substitution[1] as easy as Bash does.

Next Generation Shell - mostly there. If something of the above is missing - it's a bug and you are welcome to open an issue. I'm the author.

https://github.com/ngs-lang/ngs

Re:Writing Safe Shell Scripts (2019) by heavyset_go on Tuesday February 04, 2020 @02:51PM (#22240152)
I like this a lot. Definitely very cool, and I plan on giving it a shot when I have some time.

Just curious, but how would one do process substitution with NGS?

Re:Writing Safe Shell Scripts (2019) by IshKebab on Saturday February 01, 2020 @04:46PM (#22213465)
I don't know about process substitution, but Dart makes connecting processes together pretty easy and you can do way more fancy things than Bash let's you do, in a clean fast language with basically no gotchas.

Check out dshell: https://pub.dev/packages/dshell

Re:Writing Safe Shell Scripts (2019) by heavyset_go on Saturday February 01, 2020 @04:59PM (#22213540)
Pretty cool, thanks for pointing it out. I have some experience with Dart via Flutter development, so I'll give this a go when I have some time.
Re:Writing Safe Shell Scripts (2019) by heavenlyblue on Sunday February 02, 2020 @05:52AM (#22216352)
And now we have 3 languages...
Re:Writing Safe Shell Scripts (2019) by boring_twenties on Sunday February 02, 2020 @01:33PM (#22218469)
If your OpenWRT router has a bash shell, then you optionally installed it from packages. The default shell is Busybox, which is a minimal shell that supports few if any "bashisms." In other words, you certainly do have to be wary about what shell features you use.
Re:Writing Safe Shell Scripts (2019) by Pxtl on Saturday February 01, 2020 @04:07PM (#22213240)
PowerShell, mostly because PowerShell was designed as a mashup of Bash and C#.... And it's kind of a trainwreck in a lot of ways.

It really feels like piping and easy process invocation and compile-time directory awareness wouldn't be massively onerous to add to an existing full-featured programming language so you wouldn't have to sacrifice a good type system and powerful syntax when you want to do scripty things.

Re:Writing Safe Shell Scripts (2019) by chrisfinazzo on Saturday February 01, 2020 @05:42PM (#22213723)
As I understand it, PowerShell came about because porting the standard Linux/Unix utilities to Windows didn't work out.

PowerShell meets both requirements as it's tuned for the Windows environment, but can still play nicely with the rest of the world.

Of course, now that WSL is a thing, it's a real question why someone would want to use PS unless they had no other options.

https://www.heavybit.com/library/podcasts/to-be-continuous/e...

Re:Writing Safe Shell Scripts (2019) by sjy on Sunday February 02, 2020 @02:13AM (#22215635)
PowerShell has real data structures (arrays and hash tables), built-in functional programming tools (Select-Object, ForEach-Object, Where-Object), GUI cmdlets (Out-GridView) and direct access to .NET libraries. It’s a viable tool for many complex tasks where on Unix, you’d need to reach for Python rather than a shell.
Re:Writing Safe Shell Scripts (2019) by vips7L on Sunday February 02, 2020 @11:16AM (#22217618)
>Of course, now that WSL is a thing, it's a real question why someone would want to use PS unless they had no other options.

I use it because I only have to learn one tool, and not a ton of different ones with different UX.

The 'language' is sane, at least to me, as it's object oriented doesn't revolve around parsing strings.

Re:Writing Safe Shell Scripts (2019) by heavyset_go on Sunday February 02, 2020 @05:06AM (#22216181)
Some of the features of PowerShell seem really enticing, and I wish they would make their way over to Unix-like shells. Unfortunately, I don't know how much utility I'd get out of PowerShell on Linux, so I haven't tried it.

edit: your comment inspired me so I installed PowerShell via Snap and am going to give it a go on Linux.

Re:Writing Safe Shell Scripts (2019) by Pxtl on Sunday February 02, 2020 @10:34AM (#22217335)
To me PowerShell mixes easy access to command-line tools and higher-order object-oriented map/filter style functions. The mix between Unix-style piping from command-line tools and modern object-y mapping and filtering can feel like a dream.

That's the good part. The bad part is that it's easily one of the wartiest languages I've ever used, especially as a young language it's really got an inexcusable amount of legacy problems.

A colleague of mine (who also uses it heavily) says "two Googles per line".

Just to get sane parameter and variable checking you have to throw up a bunch of attributes and set a bunch of flags.

Be sure to set up strict mode, use cmdletbinding on your parameter blocks, and set ErrorActionPreference to "stop" in every script you write.

That and the quality of many of the first-party official PowerShell modules is appallingly low by Microsoft standards. The good side is that the .NET framework is accessible so whenever the PowerShell module is failing you, you can drop down into leveraging raw c#-style assemblies, which are much higher quality but they speak PowerShell with a very thick accent.

But I'm using it on Windows, YMMV on Linux.

I'm infatuated with the concept, but the implementation leaves a lot to be desired.

Re:Writing Safe Shell Scripts (2019) by edgyquant on Saturday February 01, 2020 @04:24PM (#22213338)
Right. Powershell is a shell though not a programming language.
Re:Writing Safe Shell Scripts (2019) by plapetomain on Saturday February 01, 2020 @06:28PM (#22213958)
That is false.

Why do you think it is not a programming language?