17 comments

9

Real programmers use the correct tool for the job.

3

I agree with the slides, one should not do complex stuff with shell scripts. However there is one further good reason to do some things in shell script: Every *nix sysadmin that is worth his/her salary MUST be able to read and maintain shell scripts. So shell is the lowest common denominator among system people.

On the other hand the poor Windows sysadmins are nowadays supposed to learn PowerShell. While it's much more powerful than CMD and WSH, the syntax is a mess.

2

Would it be accurate to say though that *nix sysadmin is gradually moving away from shell scripts for more complex tasks? Not that you could necessarily get away without the ability, but that its importance is waning. I've heard that a lot of the scripts in modern distros are python.

0

Considering bash is now mostly working on Windows natively (or at least, something resembling natively), you might be able to get away with just using that on Windows in the near future.

0

Every *nix sysadmin that is worth his/her salary MUST be able to read and maintain shell scripts.

I dare you to read and mantain a poorly written shell script. Without tests. Without documentation. Without functions. Just a list of commands to be executed sequentially salted with some conditionals here and there.

0

To be honest, I haven't encountered any poorly written shell code in my career, only good one. The worst stuff I've seen till now was written in PHP and VBScript.

2
1

I love how this got downvoats. Speaks volumes about the competency of some people.

1

The shell is all powerful and portable. I do what I want.

2

Which shell is portable?

0

Supposedly the Bourne shell has been around for a while and doesn't change much. But yeah I have been living in a sheltered fantasyland... no telling what inconsistencies are spread out there really.... maybe a google search would solve this.

Op is correct in the value of other languages though

0

The POSIX shell is a description of a portable Bourne-like shell. I'm not aware of any two conforming implementations which are fully compatible with each other.

0

What if I continue to stick to Redhat/Ubuntu builds and ignore everything else?

0

If your definition of "portable" only applies to systems you write your scripts for, then you can think whatever you like. If you want to share your scripts with people who aren't using the exact same build of the exact same version of the exact same shell, then you might want to consider restricting your scripts to only use POSIX features. Otherwise, simply state explicitly which shell your script depends on. Something I've done in the past is this:

#!/bin/SHELL
#
# Developed for SHELL version n.nn on DISTRO nn.nn.
# May not work with other shells on other systems.

It is an error if the recipient attempts to run the script on any system which doesn't have /bin/SHELL, which is fine because that would mean their system is not the same as yours. If they have SHELL at a different location they can manually edit the shebang. After that, it is up to them to ensure that their system meets your script's requirements. Make sure to clearly detail exactly what all these requirements are.

1

Obligatory xkcd:

https://xkcd.com/378/

0

But using a programming language does not mean that you are a real programmer. Real programmers can design their own tools from scratch, most programmers use tools designed by real programmers, exactly like script writers would.

0

This is awesome.