Slashdot Mirror


Adding Some Spice To *nix Shell Scripts

An anonymous reader writes "Developing GUI script-based applications is time-consuming and expensive. Most Unix-based scripts run in a CLI mode or over a secure ssh session. The Unix shells are quite sophisticated programming languages in their own right: they are easy to design and quick to build, but they are not user-friendly in the same way the Unix commands aren't (see the Unix haters books). Both Unix and bash provide features for writing user friendly scripts using various tools to build powerful, interactive, user-friendly scripts that run under the bash shell on Linux or Unix. What tools do you use that spice up your scripts on the Linux or Unix platforms?"

7 of 411 comments (clear)

  1. Stop using the Shell by Bruce+Perens · · Score: 4, Interesting

    The shell is a poor clone of 1950's algol. Today, scripting in Ruby or Python yields scripts that can handle errors with advanced facilities like exceptions, and is more maintainable, and can connect to a number of different GUIs or the web.

    1. Re:Stop using the Shell by Bruce+Perens · · Score: 3, Interesting

      I like Larry and the rest of the crew, but I think we can confidently say that Ruby is an evolution from Perl. It used to be that CPAN was a big advantage, but ruby gems have come along pretty well since then. And there's a lot to be said for the Rails framework, even more in 3.0 .

    2. Re:Stop using the Shell by Bruce+Perens · · Score: 4, Interesting

      There are times when bash/ash/dash... are all that is available or can be made available

      Because you're running Busybox. Which means it's my fault :-)

      The evolutionary successor of busybox, which I've been thinking about for a while, will not use the shell language. We can raise the bar significantly.

    3. Re:Stop using the Shell by martin-boundary · · Score: 3, Interesting
      Sorry, those advanced facilities are overhyped. How do you (eg) pipe commands together in Ruby, Python or Perl?

      AFAIK(?), none of these languages come close to the simple expressivity of cmd1 | cmd2 | cmd3 > file1.

      The shell's purpose has always been to serve the user. From the perspective of a user, advanced programming facilities like exceptions are not just useless, but can seriously get in the way.

      Programmers write pages and pages of code, and they appreciate class hierarchies, vector operations, etc. Users write throwaway scripts that are run once or twice.

      Programmers like powerful languages that make maintenance easy. Users like powerful shells that make simple interactions really easy.

    4. Re:Stop using the Shell by Bruce+Perens · · Score: 3, Interesting

      none of these languages come close to the simple expressivity of cmd1 | cmd2 | cmd3 > file1.

      This is sort of like saying that no language has anything that lets you align text like FILLER PICTURE in old Fortran. Sure, but you don't need to do it. I don't ever have to pipe to sed, because I can do File("foo.txt").read.gsub(/^Foo.*Bar$/, 'Hello!') and get the same result.

  2. Re:I only write trivial shell scripts by OA · · Score: 3, Interesting

    I agree python is lots of fun... but I do not call following script to be nontrivial.

    > In Python, you can do things like
    > junk_extension = (".temp", ".tmp", ".junk")
    > if filename.endswith(junk_extension):
    > os.remove(filename)

    Your problem is: thinking ten lines of "if" statements to look at a filename.

    This kind of things are done in 1 liner single shell command. This is too simple to bother python.

    Please read about the "find" command. especially with --exec rm '{}' \;

    Osamu

  3. Re:Pashua on OS X by iliketrash · · Score: 3, Interesting

    If you would get your facts straight there would be no need to flame.

    OS X has been UNIX 03 (SuSv3) registered and POSIX compliant since 2007.

    FYI, no version of Linux is registered Unix.

    Read these and learn:
    http://en.wikipedia.org/wiki/UNIX_03
    http://images.apple.com/macosx/technology/docs/L416017A_UNIX_TB_FF.pdf
    http://www.apple.com/server/macosx/technology/unix.html