Linked by Eugenia Loli-Queru on Fri 14th Sep 2007 23:08 UTC
General Development As a system administrator, you run across numerous challenges and problems. Managing users, disk space, processes, devices, and backups can cause many system administrators to lose their hair, good humor, or sanity. Shell scripts can help, but they often have frustrating limitations. This is where a full-featured scripting language, such as Python, can turn a tedious task into an easy one. Python is a scripting language that looks like it was made for system administrators.
Thread beginning with comment 271399
To read all comments associated with this story, please click here.
Pry bash (or tcsh) + sed/grep/awk/tr...
by meianoite on Fri 14th Sep 2007 23:27 UTC
meianoite
Member since:
2006-04-05

from my cold dead hands.

renox Member since:
2005-07-06

While I agree that Python is not a replacement for the shell, your post show the shell's problem: first there is not one shell, but several and the 'script shells' depends on a bunch of tools, all of which have variants depending on the version, OS, etc.

Most script shells are *brittle*, use them on another shell, OS, on file with spaces or weird characters and they break.

What I would like to see is a bunch of tools written in Ruby/Python which would send struct/hash through the pipe: you would have the flexibility of shell and the robustness induced by passing structures/hash around instead of 'hard to parse' text (and if you have to take into account files with weird characters in them, it's really not so easy).

Reply Parent Bookmark Score: 4

rover Member since:
2005-08-07

there is not one shell, but several and the 'script shells' depends on a bunch of tools, all of which have variants depending on the version, OS, etc.


That was pretty much the motivation for creating Perl back in the 80s. The situation has improved quite a lot since then. The end of the Unix wars brought a good deal of industry consolidation and the standardization of all those tools. Nowadays it's quite feasible to create shell scripts devoid of this kind of problems.

Even the shell is standardized. POSIX 1003.2 made /bin/sh a KornShell lookalike rather than the historical Bourne shell. That's the only shell you should use for scripts.

But the one true reason to prefer shell scripts is that way you can leverage your knowledge of the command line. Conversely, writing shell scripts will improve your skills in all the standard Unix utilities. Once you start using Perl, Python, etc. you'll have to learn two ways of doing the same thing: One way to do it interactively and one to script it.

Reply Parent Bookmark Score: 1

japh Member since:
2005-11-11

Using bash/ksh/nawk/grep etc. is fine for some things. And of course, that's where it should be used.

We have a guy at work who has pretty much the same attitude as you and he insists on doing EVERYTHING in ksh/nawk. He wrote things like XML parsers in nawk (not fully functional, of course, but they almost work for what he needs it for)

In the end, he manages to create slow, error-
prone incomprehensible stuff that would have been fairly simple, fast and easier to make correct in for example python.

So hold on to your bash, but just don't take it too far.

Reply Parent Bookmark Score: 5

jlarocco Member since:
2005-09-14

Heh, reminds me of a place I used to work. Their reporting system was kinda like this:

* The server gets a request for report X.
* Server grabs list of environment variables for report X from the DB
* Server sets the environment variables with values passed in the request.
* Server spawns ksh with the appropriate reporting script.
* Shell script uses IO redirection to send SQL to Oracle
* Shell script parses the data and stores it to a temp file.
* The server reads the temp file and sends it back to the client.

The great part is, the guy who actually "designed" that part, left for some other job and nobody else there knew Korn shell.

Reply Parent Bookmark Score: 1

wirespot Member since:
2006-06-21

So hold on to your bash, but just don't take it too far.


I think that's exactly what the articles suggests. There's no implying that Python should replace Bash, but complement it for those scripts that are too much for Bash. If anything, it attempts to replace Perl, not Bash.

Reply Parent Bookmark Score: 3

libray Member since:
2005-08-27

The great thing about using shell scripts to their maximum capacity is that there are no modules. With perl and python, the suggestion for common use involves a module, which may or may _not_ be on the system.

You will find that once you go down the path of attempting to install a module for an interpreted language, your systems can become out of sync with one another. Not so with shell scripts. A Bourne shell function works as well on one system as it certainly will another.

Even when programming to capture missing modules, have you found that exception use of import (python) or require (perl) involves a lot of alarm bells and whistles. And you do this so that you catch the exception to be able to begin the installation of the module dependencies and module rather than actually getting on with better things to do?

Reply Parent Bookmark Score: 2