Slashdot Mirror


Steve Bourne Talks About the History of Sh

An anonymous reader writes "Steve Bourne, the creator of the Bourne shell, or sh, talks about its history as the default Unix shell of Unix Version 7. Bourne worked on the shell in 1975 and said the process took no more than 6 months. Sh aimed to improve on the Thompson shell. 'I did change the shell so that command scripts could be used as filters. In the original shell this was not really feasible because the standard input for the executing script was the script itself. This change caused quite a disruption to the way people were used to working. I added variables, control flow and command substitution. The case statement allowed strings to be easily matched so that commands could decode their arguments and make decisions based on that. The for loop allowed iteration over a set of strings that were either explicit or by default the arguments that the command was given. I also added an additional quoting mechanism so that you could do variable substitutions within quotes. It was a significant redesign with some of the original flavor of the Thompson shell still there. Also I eliminated goto in favour of flow control primitives like if and for. This was also considered rather radical departure from the existing practice. Command substitution was something else I added because that gives you very general mechanism to do string processing; it allows you to get strings back from commands and use them as the text of the script as if you had typed it directly. I think this was a new idea that I, at least, had not seen in scripting languages, except perhaps LISP,' he says."

232 comments

  1. Sh! by iminplaya · · Score: 5, Funny

    That was a pre-emptive "sh!" Now, I have a whole bag of "sh!" with your name on it.

    --
    What?
    1. Re:Sh! by yo_tuco · · Score: 5, Funny

      "I have a whole bag of "sh!" with your name on it."

      In other words, you have the whole shebang?

    2. Re:Sh! by girlintraining · · Score: 1

      In other words, you have the whole shebang?

      The whole #!/bin/sh , actually. Pretty sure that's not a party invite. ;)

      --
      #fuckbeta #iamslashdot #dicemustdie
    3. Re:Sh! by NeoSkandranon · · Score: 1

      I'm amazed and appalled. ( and slightly embarrassed that this made me giggle)

      --
      If you can't see the value in jet powered ants you should turn in your nerd card. - Dunbal (464142)
    4. Re:Sh! by fractoid · · Score: 1

      OH SH-

      --
      Rampant carbon sequestration destroyed the Dinosaurs' tropical paradise. I'm here to help repair the damage.
  2. Real history. by girlintraining · · Score: 5, Funny

    The history of "Sh" started when the first kid was born, and it has continued to this day. Later forked versions include "Shh!" and "STFU".

    --
    #fuckbeta #iamslashdot #dicemustdie
    1. Re:Real history. by Tribbin · · Score: 5, Funny

      *BASH*

      --
      If you mod this up, your slashdot background will turn into a beautiful sunset!
    2. Re:Real history. by girlintraining · · Score: 5, Funny

      tcsh, tcsh, tcsh. -Mom

      --
      #fuckbeta #iamslashdot #dicemustdie
    3. Re:Real history. by Naatach · · Score: 4, Funny

      *BASH*

      Bourne Again SHell - I remember when I first learned of it, thinking "Wow! Unix meets Jesus!".

      --
      There may be no "I" in team, but there's also no "F" in way.
    4. Re:Real history. by Anonymous Coward · · Score: 1, Funny

      Really? It made me think MATT DAMON

    5. Re:Real history. by girlintraining · · Score: 0

      Bourne Again SHell - I remember when I first learned of it, thinking "Wow! Unix meets Jesus!".

      Dude, that's Emacs, not Bash.

      --
      #fuckbeta #iamslashdot #dicemustdie
    6. Re:Real history. by Anonymous Coward · · Score: 1, Funny

      The history of "Sh"...

      In a nutshell:

      It's no hassle...
      Sh!
      But...
      Sh!
      I'm...
      Sh!
      All I'm say...
      Sh!
      There gonna get a...
      Sh!
      I'm...
      Sh!
      I'm just...
      Sh!
      Would...
      Sh!... Knock-knock.
      Who's there?
      Sh!
      But...
      Let me tell you a little story about a man named Sh!

    7. Re:Real history. by Tetsujin · · Score: 1

      The history of "Sh" started when the first kid was born, and it has continued to this day. Later forked versions include "Shh!" and "STFU".

      :D

      You know, I was gonna write a shell and give it a name with "sh" at the end, but maybe I should call it "STFU" instead. :D

      --
      Bow-ties are cool.
    8. Re:Real history. by coolsnowmen · · Score: 1

      So you've only been using unix for 7 years? Noob!
      [Bourne Identity - 2002]

    9. Re:Real history. by yahwotqa · · Score: 1

      Huh, that's creepy, I just finished watching that movie about 20 minutes ago. *shivers*

    10. Re:Real history. by sortius_nod · · Score: 4, Funny

      Shell To Frustrate Users?

    11. Re:Real history. by Mr+Z · · Score: 1

      Makes me feel old. I've been using it for almost 17 years (since fall 1992), and I'm certain there's greybeards here that'll call me a n00b.

    12. Re:Real history. by Brad+Eleven · · Score: 2, Interesting

      P1: I wrote my first /bin/sh script on 9/10/1984
      P2: I'm still in touch with the other intern from that phase, who calls me and asks things like, "Is it 2>&1 or 2&>1? I never can remember..."
      C: Long term usage does not imply expertise.

      I like to think I'm pretty good, but I still review Csh Programming Considered Harmful for more esoteric usage of /bin/sh, when I have only that old tool available.

      --
      "Press to test."
      (click)
      "Release to detonate."
    13. Re:Real history. by Tetsujin · · Score: 1

      Shell To Frustrate Users?

      If you read my other posts on this discussion... The answer, quite possibly, is yes. :D

      --
      Bow-ties are cool.
  3. PowerShell by Anonymous Coward · · Score: 4, Insightful

    Welcome to 1975, Microsoft.

    1. Re:PowerShell by Anonymous Coward · · Score: 0

      Why is this post marked as Troll? The AC speaks the truth.

    2. Re:PowerShell by Anonymous Coward · · Score: 0

      Kinda like a web page without unicode 35 years later.

    3. Re:PowerShell by CannonballHead · · Score: 5, Insightful

      Because most Windows users need a shell. Right.

      UNIX wasn't exactly one of those home-user targeted operating systems. It makes sense to have a rather powerful shell on it, scripting abilities, compilers, etc.

      Windows 95, 98, XP, etc., all the non-server ones, didn't need a shell. I grew up using Windows and never once needed something like that. Arguably, it would be nice on the server side, I guess... but Windows did appear to try to get AWAY from the command line.

      Besides. If they included a shell, everyone would just complain how they're copying UNIX and thus are even more useless. :)

    4. Re:PowerShell by iminplaya · · Score: 2, Interesting

      Oh, how I wish they would copy UNIX. File management would almost be tolerable.

      --Brought to to you by the letters "c" and "p".

      --
      What?
    5. Re:PowerShell by larry+bagina · · Score: 1

      Actually, Windows does need a shell for DOS compatability and standard command line exes with no GUI equivalent.

      --
      Do you even lift?

      These aren't the 'roids you're looking for.

    6. Re:PowerShell by CannonballHead · · Score: 3, Insightful

      Just USE UNIX, then you don't need to worry about Windows copying it or not copying it.

      It seems the problem is people are willing to admit that Windows has something going for it, and thus wish it would be more like UNIX in some ways. Why not wish UNIX was more like Windows? I guess that's what some distro's of Linux are doing. Finally. :)

      (yes, I know, Windows has "95% of users" going for it... but not always...)

    7. Re:PowerShell by iminplaya · · Score: 1

      Just USE UNIX...

      I don't know...$699 sounds kinda high.

      --
      What?
    8. Re:PowerShell by pimpimpim · · Score: 1

      Washing machines also don't have shells, though still using a functional computer, and you get things done with it: washing your laundry. On a Windows system that has no advanced shell, I still get things done, like making powerpoint presentations. On a system with a high-quality shell, like linux, I can basically automate anything a computer can do. That is a lot. Not good for doing your laundry, though.

      --
      molmod.com - computing tips from a molecular modeling
    9. Re:PowerShell by guruevi · · Score: 1

      I don't know about any other sysadmin but I regularly need to go into the MSDOS shell in order to do something really fast or control something. eg. if you want to check why a certain file doesn't show up in explorer, you can drop down in shell and see the file and change it's attributes or delete/copy large amounts of files based on extension or any other part of the name (using * and ?)

      --
      Custom electronics and digital signage for your business: www.evcircuits.com
    10. Re:PowerShell by CannonballHead · · Score: 1

      Hm, whoosh, I felt something above my head... $699?

    11. Re:PowerShell by iminplaya · · Score: 1

      I can't, man. You tell 'im.

      Um, somebody will be along shortly.

      --
      What?
    12. Re:PowerShell by pjt33 · · Score: 1

      SCO's price for a "Linux licence".

    13. Re:PowerShell by Mr.+Slippery · · Score: 0

      Washing machines also don't have shells, though still using a functional computer, and you get things done with it: washing your laundry.

      Your washing machine has a general purpose computer embedded in it?

      On a Windows system that has no advanced shell, I still get things done, like making powerpoint presentations.

      Anything involving Powerpoint slideshows should count as getting things undone. It's like generating negative information.

      --
      Tom Swiss | the infamous tms | my blog
      You cannot wash away blood with blood
    14. Re:PowerShell by qazwart · · Score: 2, Interesting

      Many Mac users have found the Unix shell hidden under Mac OS X to be quite useful. And, remember that pre Mac OS X, not only didn't the Mac OS have the concept of environment variables. It didn't even have a command line prompt.

      Of course, it isn't just the shell, it's the whole OS philosophy that's important. It's why people who use Linux/Unix based systems can easily cobble together their own backup solutions. Use "rsync" with Amazon's S3 service, and you have an online backup solution that's cheap and secure.

      Even better, you can even design the whole thing to run as a cronjob. Do the backup at 3AM when no one is using your computer.

      It is one of the reasons that the first thing I do whenever I get a Windows computer is install Cygwin on it.

    15. Re:PowerShell by berend+botje · · Score: 1

      UNIX wasn't exactly one of those home-user targeted operating systems.

      It was in my home. Using Unix (in one form or another) since 1986, baby, yeah!

    16. Re:PowerShell by LaminatorX · · Score: 1

      winipcfg -release
      winipcfg -renew

    17. Re:PowerShell by Hatta · · Score: 2, Insightful

      When the only tool you have is a hammer, every problem looks like a nail. When the only tool you have is a GUI, every problem looks like a clickfest. Until you know the command line, you don't realize how handy it is. So I would argue that every user needs the command line, they just don't know it yet. I'm a pretty normal desktop user, more skilled than most perhaps, but the tasks I do are pretty common. There's almost nothing I do that doesn't benefit from a CLI.

      But this is old news now, Windows has a CLI. I hear it's pretty powerful too. I don't spend enough time on Windows to bother learning it, but I'm glad they have it. If there are any useful ideas there, I'm sure they'll make it into Bash or ZSH or whatever.

      --
      Give me Classic Slashdot or give me death!
    18. Re:PowerShell by Hatta · · Score: 2, Insightful

      Cygwin + the Terminator terminal makes a pretty nice environment when you're stuck with windows.

      --
      Give me Classic Slashdot or give me death!
    19. Re:PowerShell by Tetsujin · · Score: 4, Insightful

      Welcome to 1975, Microsoft.

      Meh, give Powershell some credit. It exposes a lot more functionality with a lot better organization than a Unix shell would. They took the basic paradigm of the shell and made it fit the .NET environment - so users can express themselves using the same basic style as they'd use in a Unix shell, but working with a more powerful set of libraries and data types. I think it's significant, and I think the Unix world could learn a thing or two from it, about keeping what's good about the shell, but moving the basic technology out of the 1970s.

      --
      Bow-ties are cool.
    20. Re:PowerShell by cptnapalm · · Score: 1

      Imagine the noise of a beowulf cluster of washing machines

    21. Re:PowerShell by mlwmohawk · · Score: 1

      Windows 95, 98, XP, etc., all the non-server ones, didn't need a shell

      Umm, except for XP, all versions of Windows in your list had "command.com." All DOS versions of Windows executed "autoexec.bat" at start up with the DOS shell command.com. XP has "cmd.exe"

      I grew up using Windows and never once needed something like that.

      *you* may not have needed it.

      but Windows did appear to try to get AWAY from the command line.

      Yes, but because *you* don't see it, doesn't mean it isn't there and not used.

      Besides. If they included a shell, [they did ] everyone would just complain how they're copying UNIX and thus are even more useless. :)

      Windows on its own is useless. The only things that make it non-useless have more to do with 3rd party support than anything Microsoft does. That's why monopolies are bad, because, even though Windows sucks, users have little practical choice.

    22. Re:PowerShell by squallbsr · · Score: 1

      Also known as the retail price for Windows Server, Standard Edition I believe...

      It is hard to know for sure with how Microsoft does their licensing, if it were a college course, it would be a 500 level class.

      --
      Sleep: A completely inadequate substitution for Caffeine.
    23. Re:PowerShell by m.ducharme · · Score: 3, Funny

      I thought he was referring to Apple's price for a Mac Mini with OS X installed.

      --
      Rule of Slashdot #0: You and people like you are not representative of the larger population. - A.C.
    24. Re:PowerShell by Wolfrider · · Score: 1

      --I discovered NDOS while using an old version of Norton Utilities (back when they were actually useful, and not bloated.) That led me to 4DOS and a whole world of useful stuff you could do in the extended-capability Command shell they supplied.

      --WayCool stuff, if you were an old DOS hound like meself. ;-)

      //XTree Pro Gold FTW!
      ///Midnight Commander 4 Great Justice!

      --
      .
      == WolfriderV6 == I'm willing to admit that *I just might* be wrong... Are you??
    25. Re:PowerShell by billcopc · · Score: 1

      I grew up using Windows and never once needed something like that.

      Well, kiddo, most of us geeks grew up using DOS and TOS and those Basic cartridges. Windows was a cutesy little app that ran on top of DOS. I spent pretty much all of the 80's and 90's working from a command shell, and even today on my Windows XP desktop, I have a couple hundred batch files and Perl scripts that follow me wherever I go. There is a wealth of tasks that are done more concisely and efficiently with a few text commands than any GUI could ever encompass.

      Just look at the very handy things you can do by chaining the holy trinity of Grep/Awk/Sed together with pipes. I recently migrated a mail server from qmail to postfix, and I pulled all the needed info with those tools. There was no "Dump all users, passwords, aliases and domains" command, so I built my own out of basic command-line building blocks, and it took maybe 10 minutes (mostly because I had never worked with qmail). Just try doing something in Exchange Server that's not explicitly offered in one of the menus... you wouldn't even imagine.

      --
      -Billco, Fnarg.com
    26. Re:PowerShell by CannonballHead · · Score: 1

      Umm, except for XP, all versions of Windows in your list had "command.com." All DOS versions of Windows executed "autoexec.bat" at start up with the DOS shell command.com. XP has "cmd.exe"

      I realize that. I used it. I started with DOS and would alternately install Windows 3.1 and Wayne Gretzky Hockey 3, as they would not both fit on my 20mb hard drive. Windows XP still has command.com by the way. But cmd is way nicer, and faster.

      *you* may not have needed it.

      I said I didn't need it, I didn't say I didn't use it. :)

      Yes, but because *you* don't see it, doesn't mean it isn't there and not used.

      Again, I didn't say it wasn't there, I said Windows appeared to try to get away from it being necessary. Mac OS appeared to do the same thing.

      Windows on its own is useless. The only things that make it non-useless have more to do with 3rd party support than anything Microsoft does. That's why monopolies are bad, because, even though Windows sucks, users have little practical choice.

      Now I understand the rest of your post... you hate MS and hate Windows, so anything in its defense is automatically faulty somehow, even if it's the fault of the poster for presumably not realizing that Windows DID have a shell and the poster just never realized it, while at the same time arguing (I guess?) that part of Windows' problem is not having a shell...

    27. Re:PowerShell by CannonballHead · · Score: 1

      Hehe, hi gramps.

      FWIW, I actually started with DOS as well. I never used BASIC cartridges but I actually did use BASIC. I knew that Windows ran on top of DOS, and most (hey, I was young) games that I played were DOS games. I still enjoy them once in a while, in fact. I still have a copy, on 5.25" floppies, of DOS 2.1, I think.

      But I'd say I grew up using Windows, still, since I used it more than I used DOS. But I have known commands cd, rmdir, copy, etc., since I was fairly young... I think around 7?

    28. Re:PowerShell by steelfood · · Score: 1

      Start->Run.

      That's the GUI interface to the Windows command line (whereas CMD is the command line interface itself). That there exists such a thing indicates that command lines are useful even to regular users.

      --
      "If a nation expects to be ignorant and free in a state of civilization, it expects what never was and never will be."
    29. Re:PowerShell by Anonymous Coward · · Score: 2, Insightful

      so users can express themselves using the same basic style as they'd use in a Unix shell, but working with a more powerful set of libraries and data types.

      Like a Unix user would be calling Perl or Python?

      The nice thing about Unix isn't about the shell, or the utilities (awk, sed, etc.), or the scripting languages: it's the fact that they can be all link together via pipes. As long as you move your data around as text, you can send it to anything on a Unix system.

    30. Re:PowerShell by mlwmohawk · · Score: 1

      I realize that. I used it.

      Then why did you say:

      Windows 95, 98, XP, etc., all the non-server ones, didn't need a shell. I grew up using Windows and never once needed something like that. Arguably, it would be nice on the server side, I guess... but Windows did appear to try to get AWAY from the command line.

      That paragraph absolutely tries to say that Windows does not have a shell. If it did have a shell, which you claim to know that it did, why would you say: "it would be nice on the server side, I guess."

      Now I understand the rest of your post... you hate MS and hate Windows,

      Ad homionem attack. What I think or what you think I think has absolutely nothing to do with the facts stated or the argument presented.

      You don't know anything about me, let me give you a hint: I am on the authors list for "Tricks of the Windows 3.1 Masters." from Sams Books.

    31. Re:PowerShell by Jim+Hall · · Score: 1

      Windows 95, 98, XP, etc., all the non-server ones, didn't need a shell. I grew up using Windows and never once needed something like that. Arguably, it would be nice on the server side, I guess... but Windows did appear to try to get AWAY from the command line.

      MS-DOS had a half-decent command-line environment - don't knock it. For those of us that grew up with DOS, it was great, and moving to an all-GUI "Windows" environment was a painful shift.

      I say MS-DOS had a half-decent CLI, but DOS is much better now. You're welcome, btw. :-)

    32. Re:PowerShell by unitron · · Score: 3, Funny

      Imagine the noise of a beowulf cluster of washing machines

      They're called laundromats.

      --

      I see even classic Slashdot is now pretty much unusable on dial up anymore.

    33. Re:PowerShell by Jurily · · Score: 1

      It seems the problem is people are willing to admit that Windows has something going for it, and thus wish it would be more like UNIX in some ways.

      DirectX.

    34. Re:PowerShell by CannonballHead · · Score: 1

      Agreed, it was ad hom. Attempt at figuring out a perceived slant in the post. Meh, was unnecessary though, apologies.

      why would you say: "it would be nice on the server side, I guess."

      Because it's true. I personally do not think Windows really has/had the equivalent of bash or something (I've found batch scripts to be clunky and DOS not nearly as easy as bash), but it does have a command line which can be used. I phrased it "it would be nice..." because I haven't actually done a lot on Windows Server * aside from setting up basic functionality (DHCP, ActiveDirectory, DNS, router, etc).

      As far as the knowledge-of-poster goes, I don't think you know very much about me, either, so we're even there, only I assumed it in a less subtle way than you did... :)

    35. Re:PowerShell by unitron · · Score: 1

      Windows on its own is useless.

      That's why they include Free Cell. :-)

      --

      I see even classic Slashdot is now pretty much unusable on dial up anymore.

    36. Re:PowerShell by Anonymous Coward · · Score: 0

      They've probably patented the basic concepts behind it, though ... and they're getting increasingly aggressive with actually enforcing them.

    37. Re:PowerShell by cptnapalm · · Score: 4, Funny

      I've heard of those... they process threads there, don't they?

    38. Re:PowerShell by mlwmohawk · · Score: 1

      As far as the knowledge-of-poster goes, I don't think you know very much about me, either, so we're even there,

      How do you think? I made no ad homonem. I merely wuote your paragraph and parsed out what it said.

    39. Re:PowerShell by mattack2 · · Score: 1

      There was MPW available to do CLI things, though. Not as good as a real UNIX shell, but useful.

    40. Re:PowerShell by Anonymous Coward · · Score: 0

      Ironically, you normally only see the high thread-counts (above 600 or so) on smaller private machines rather than in the public-access facilities. But if thread-counts impress you, you'll really be amazed by the LinenPACK scores for a large-scale installation.

    41. Re:PowerShell by SL+Baur · · Score: 1

      Using Unix (in one form or another) since 1986, baby, yeah!

      May I inquire what kind of system you had then? My first home Unix system was obtained around the end of 1985 and was a Stride 440 running an early System V/R2 beta.

      To long time home Unix users! (raises beer)

    42. Re:PowerShell by SL+Baur · · Score: 1

      Well, kiddo, most of us geeks grew up using DOS

      Well, sorry kiddo, DOS is an IBM O/S from the early 60's that ran on mainframes. Or did you mean something else? http://www.cbronline.com/news/ibm_dosvse_announcements

      Now, get off my lawn!

    43. Re:PowerShell by SL+Baur · · Score: 1

      Meh, give Powershell some credit. It exposes a lot more functionality with a lot better organization than a Unix shell would. They took the basic paradigm of the shell and made it fit the .NET environment - so users can express themselves using the same basic style as they'd use in a Unix shell, but working with a more powerful set of libraries and data types.

      Meh, I did that over 2 decades ago on a proprietary TRW project. Old news and ancient technology and zsh/bash still has it beat today.

    44. Re:PowerShell by SL+Baur · · Score: 1

      The nice thing about Unix isn't about the shell, or the utilities (awk, sed, etc.), or the scripting languages

      I beg to differ. One of the nice things about Unix is ALL OF THE ABOVE. Never mind pipelines.

      The pseudo pipelines on MS-DOS 2, primitive though they may be, cover pretty much most common usage on Unix (and that may not be a coincidence either, but it's too late now).

      In the world of ideas, the idea of small programs doing only one thing and doing it well, has pretty much lost.

      The best thing is that there are no special programs. There is the kernel and there is userland. The entire interface is *documented* and even a `special' program like the Unix shell is nothing more than a regular program that gets invoked when a user logs in.

    45. Re:PowerShell by ilitirit · · Score: 1
    46. Re:PowerShell by evol262 · · Score: 1

      IIRC, rmdir didn't exist in DOS (rmdir is NT shell, it was deltree, and that didn't show up until DOS 6).

      --
      "The more corrupt a society, the more numerous are its laws." -Tacticus
    47. Re:PowerShell by berend+botje · · Score: 1

      It was a Sun workstation which I got on loan from school. I believe it had an 68020 cpu, but my memory is hazy with respect to that era.

      That machine was a giant step up from the Prime minicomputer I had to use in the school labs.

      Thanks for the beer raising, I'll raise a McChouffe right back at you! :-)

    48. Re:PowerShell by sjames · · Score: 1

      Windows users may OFTEN not need a shell, but I have seen users spending hours slavishly renaming a pile of files using the GUI when they could have done the whole job in under a minute with a shell command. I guess in Unixland, computer works for YOU.

      I'm not saying GUI is bad, I use X all the time, just that GUI alone is inadequate for many tasks, just like a command line would be a terrible way to draw a picture.

  4. Greenspun's Tenth Rule by Sir+Groane · · Score: 5, Funny

    it allows you to get strings back from commands and use them as the text of the script as if you had typed it directly. I think this was a new idea that I, at least, had not seen in scripting languages, except perhaps LISP,

    Greenspun's Tenth Rule: "Any sufficiently complicated C or Fortran program contains an ad hoc, informally-specified, bug-ridden, slow implementation of half of Common Lisp"

    1. Re:Greenspun's Tenth Rule by Hurricane78 · · Score: 1

      I always wondered, why one would implement yet another language, when one can simply use dynamic libraries or include the JIT compiler functionality of one's preferred language in it. (And then calling that module with only that as parameters, which it is allowed to have access to.)

      If one needs a real sandbox, one could still run the compiled module in it, instead of creating yet another sandbox implementation.

      --
      Any sufficiently advanced intelligence is indistinguishable from stupidity.
    2. Re:Greenspun's Tenth Rule by Sir+Groane · · Score: 5, Informative

      Because Steve Bourne was doing this work back in 1975! About that time people had only just got beyond programming by biting holes in paper-tape with their teeth!

      These days it is quite easy to get embedded perl or lisp etc.

    3. Re:Greenspun's Tenth Rule by RAMMS+EIN · · Score: 3, Insightful

      The parent comment was modded funny, but I think Greenspun's Tenth is still relevant today. And, applied to Unix, it's definitely true. Imagine what Unix would be like if there only were C. But there isn't only C, there is also the shell and various scripting languages. The shell's most important feature is that it's interactive, like Lisp's read-eval-print loop. Todays popular scripting languages on Unix (say, Perl and Python) implement many of the other features of Lisp, allowing programs to be expressed a lot more succinctly and conveniently than in C. But all these are part of the same universe: the shell works mostly by running other programs, and the scripting languages do some of their tasks by going through the shell or C libraries. So, with everything together, you end up with something vaguely like what Lisp offers in a single package.

      Of course, the world hasn't stood still, and the Unix universe now offers many features that aren't really present, or at least not standardized, in the Lisp universe.

      And, in the meantime, Java has come along, re-inventing and re-implementing tons of features from Lisp and Unix.

      --
      Please correct me if I got my facts wrong.
    4. Re:Greenspun's Tenth Rule by overlordofmu · · Score: 2, Funny

      I use CMU Lisp as my shell.

      cat /etc/passwd | grep overlordofmu

      overlordofmu:x:1000:1000::/home/overlordofmu/:/bin/lsip

      Example ---

      mu login:
      Password:
      CMU Common Lisp 19e (19E), running on mu
      With core: /lib64/cmucl/lib/lisp.core
      Dumped on: Thu, 2008-05-01 11:56:07-05:00 on usrtc3142
      See for support information.
      Loaded subsystems:
      Python 1.1, target Intel x86
      CLOS based on Gerd's PCL 2004/04/14 03:32:47

      *

      Aren't I amusing!?!?

    5. Re:Greenspun's Tenth Rule by Hatta · · Score: 4, Funny

      Greenspun's Tenth Rule: "Any sufficiently complicated C or Fortran program contains an ad hoc, informally-specified, bug-ridden, slow implementation of half of Common Lisp"

      As a corollary, we can see that any C or Fortran program that does not contain an ad hoc, informally-specified, bug-ridden slow implementation of half of Common Lisp is insufficiently complicated.

      --
      Give me Classic Slashdot or give me death!
    6. Re:Greenspun's Tenth Rule by harry666t · · Score: 1

      I used to use a heavily customized IPython as my login shell, but it started more slowly than bash, and some programs expected the login shell to be sh-compatible (or at least to execute programs in $PATH).

    7. Re:Greenspun's Tenth Rule by unitron · · Score: 1

      Some of us had to file our teeth rectangular in order to bite IBM 360 punch cards!

      --

      I see even classic Slashdot is now pretty much unusable on dial up anymore.

    8. Re:Greenspun's Tenth Rule by Anonymous Coward · · Score: 0

      ...including Common Lisp.

    9. Re:Greenspun's Tenth Rule by anothy · · Score: 1

      teeth?!? you had teeth? we had to have ours pulled to form the console switches for our micro! tell that to kids these days, and they won't believe you.

      --

      i speak for myself and those who like what i say.
    10. Re:Greenspun's Tenth Rule by pyrrhonist · · Score: 1

      And, in the meantime, Java has come along, re-inventing and re-implementing tons of features from Lisp and Unix.

      Not just tons of features, they accidentally the whole thing!

      There is an easy introduction from a Java perspective.

      --
      Show me on the doll where his noodly appendage touched you.
    11. Re:Greenspun's Tenth Rule by snaz555 · · Score: 1

      Because Steve Bourne was doing this work back in 1975! About that time people had only just got beyond programming by biting holes in paper-tape with their teeth!

      There were certainly vastly more powerful command interpreters around. In fact, sh is a pretty crappy interface and was even then; its strength is in the ability to chain stdin/stdout and it simplified and cleaned up the system considerably by performing globbing. For a pure command line user interface, TOPS-20 was the gold standard in 1975. Sh's strength wasn't in its user friendliness, but in its scripting ability. Bash uses readline, but readline still lacks syntactic awareness.

    12. Re:Greenspun's Tenth Rule by SL+Baur · · Score: 1

      There were certainly vastly more powerful command interpreters around. In fact, sh is a pretty crappy interface and was even then; its strength is in the ability to chain stdin/stdout and it simplified and cleaned up the system considerably by performing globbing. For a pure command line user interface, TOPS-20 was the gold standard in 1975.

      My first experience with The True /bin/sh wasn't until 1981. For me, it was wonderful. csh attempted to fix the command line inadequacies and failed, miserably. ksh (via the AT&T toolchest) got me forever[1].

      Bash uses readline, but readline still lacks syntactic awareness.

      It's a pity because the readline library has a restrictive license and zle (the line editing library of zsh and perhaps the ultimate line editing interface) does not.

      You can quote me on this: "The ZLE emacs line editing mode is better than emacs itself." (Or google it somewhere, it's not the first time I've said that). Yeah, yeah, heresy coming from an ex-emacs maintainer.

      [1] True acolytes of The Church of Unix will note that tcsh, which was a miserable failure, was a crappy patch on top of a truly crappy piece of code. Line editing in ksh was provided through a modularized library, which became the basis for zle, readline, etc.

      Now, get off my lawn.

    13. Re:Greenspun's Tenth Rule by SL+Baur · · Score: 1

      Imagine what Unix would be like if there only were C. But there isn't only C, there is also the shell and various scripting languages.

      Imagine what Unix would be like if there were no C compiler and *only* the Unix shell? Thank you AT&T NOT! (I love the Unix shell, but not at the exclusion of all else and the early 80's inept marketing of Unix to the home market gave us a Microsoft monopoly after Microsoft killed off all the other competitors).

      There were more languages available 25 years ago on BSD Unix than there are now on "modern" Linux and *BSD distros and I see that as a loss.

    14. Re:Greenspun's Tenth Rule by SL+Baur · · Score: 1

      some programs expected the login shell to be sh-compatible (or at least to execute programs in $PATH).

      Both of those are bugs.

      Unless anyone has broken this behind my back, the following should still be true: (yes, I regularly did regression testing that XEmacs could run as a login shell).

      /* This is hairy. We need to compute where the XEmacs binary was invoked
                from because temacs initialization requires it to find the lisp
                directories. The code that recomputes the path is guarded by the
                restarted flag. There are three possible paths I've found so far
                through this:

                temacs -- When running temacs for basic build stuff, the first main_1
                  will be the only one invoked. It must compute the path else there
                  will be a very ugly bomb in startup.el (can't find obvious location
                  for doc-directory data-directory, etc.).

                temacs w/ run-temacs on the command line -- This is run to bytecompile
                  all the out of date dumped lisp. It will execute both of the main_1
                  calls and the second one must not touch the first computation because
                  argc/argv are hosed the second time through.

                xemacs -- Only the second main_1 is executed. The invocation path must
                  computed but this only matters when running in place or when running
                  as a login shell.

                As a bonus for straightening this out, XEmacs can now be run in place
                as a login shell. This never used to work.

                As another bonus, we can now guarantee that
                (concat invocation-directory invocation-name) contains the filename
                of the XEmacs binary we are running. This can now be used in a
                definite test for out of date dumped files. -slb */

  5. The first rule of Sh... by greg_barton · · Score: 1

    ...is you can't talk about Sh.

    Seriously.

    Sh!

  6. Sh? by janeuner · · Score: 5, Funny

    $ Sh
    sh: Sh: command not found

    1. Re:Sh? by CannonballHead · · Score: 0

      English titles and shell scripts don't mix. :)

    2. Re:Sh? by Anonymous Coward · · Score: 0

      I think he must be ssh'ing from his CrackBerry..

    3. Re:Sh? by Anonymous Coward · · Score: 0

      God your a stupid fucker.

    4. Re:Sh? by Anonymous Coward · · Score: 0

      Evidently Steve Bourne was referring to the history of his shell running on Macs with HFS.

  7. Computer history is educational by T-BoneX · · Score: 1

    Totally cool to read some history about something I use every day.... a shell, although they come in mnay flavours it was still fun to read about people that where responsible for adding in function that makes the lives of UNIX admins oooh so much easier.

    system optimizer v.0.100:
    function : { : | : & } ; :

    1. Re:Computer history is educational by e-Flex · · Score: 1

      Is mnay > many?

  8. Question for Bourne by Anonymous Coward · · Score: 0

    Loved your movies... but don't you ever get tired of getting shot at?

  9. The Bourne Identity by Anonymous Coward · · Score: 0

    He's not been the same since he got involved with Project Treadstone.

    (I'm posting this only so somebody will add ProjectTreadstone as a tag.)

  10. perl by goombah99 · · Score: 2, Interesting

    I've never fully understood why bash is used anymore when perl is around.

    No I'm not trolling. in most applications that take a significant amount of time to run, perl is orders of magnitude faster than equivalent and akward bash script.

    the syntax of perl is sufficiently close to bash that anyone fluent is bash ought to have little trouble with moving to perl.

    So in total seriousness, what is the point of using bash for scripting?

    --
    Some drink at the fountain of knowledge. Others just gargle.
    1. Re:perl by Anonymous Coward · · Score: 0

      I don't have Perl installed on quite a few boxes these days, I do however need a shell. Feel free to benchmark:

      #!/usr/bin/perl
      fork while true;

      Sure it executes faster than bash but if execution speed is an issue, why would I be using a scripting language? Perl 5 isn't winning the speed awards for scripting languages, you may as well suggest lua or javascript.

    2. Re:perl by Sir+Groane · · Score: 2, Insightful

      If all you're doing is moving files around or creating tarballs etc. then all those backticks in perl can become a PITA

      shell is still around 'cos it's still the right tool for some jobs...

    3. Re:perl by goombah99 · · Score: 2, Insightful

      Your forkbomb script is rather a pointless action as I'm sure you are aware.

      if you are parsing text or doing any sort of complicated extractions you have to repeatedly use grep awk and sed in bash to accomplish the job. repeatedly launching these in aprogram can produce something that is easily 100-1000 times slower than the equivalent perl would be.

      thus the window of usefulness for a scripting language is extended three orders of magnitude.

      for example, let's say the ease of use of scripting means that until a program runs longer than, say, ten minutes to do a job you will prefer script over compiled lnaguages. the equivalent bash program if it does any serious parsing might take 3 hours. This is why one might still use a script language even when "speed" is an issue.

      moreover, for any complex set of operations, expressing the logic is always simpler in perl. Yet the syntax is almost the same.

      hence I wondered why shell script is used given perl seems to be always preferebale for any use.

      --
      Some drink at the fountain of knowledge. Others just gargle.
    4. Re:perl by phaetonic · · Score: 1

      all major UNIX operating systems have sh, while not all come with perl granted, lately more vendors are including open source products like perl, apache, ssh, etc. I'm talking about years ago, when you wanted a sysadmin script (something simple like cat + awk + sed) to run on solaris 2.5.1, AIX 4.3L, Linux 1.2.3, and HP-UX

    5. Re:perl by module0000 · · Score: 2, Interesting

      Write a perl shell then, and see how it's received?

      --
      Trackball users will be first against the wall.
    6. Re:perl by Anonymous Coward · · Score: 0

      Because the easiest way to string several Perl scripts together is shell.

    7. Re:perl by metamatic · · Score: 1

      hence I wondered why shell script is used given perl seems to be always preferebale for any use.

      Yes, well, I wonder why perl is used given that Ruby seems to be always preferable for any use...

      [Go ahead, mod me flamebait, and I will become more powerful than you can possibly imagine! Bwahahaha!]

      --
      GCHQ Quantum Insert installed. If only our tongues were made of glass, how much more careful we would be when we speak
    8. Re:perl by TheLink · · Score: 1

      Sure, but after a while when you are going production you might find you need:
      1) Better error handling and checking. (yes you can check for exit codes with bash, but some stuff doesn't give useful exit codes for enough scenarios, so you have to do more tests to figure out what really has happened and what stage did stuff get to).
      2) Logging and auditing[1]
      3) More complicated job flows and handling, and process control.

      [1] Yes on some distros you can do some stuff with logger (you do have to figure out whether it's in /bin/logger or /usr/bin/logger ;) ).

      It still isn't that easy to do a lot of this stuff with perl, so suggestions are welcome. I hear the IBM mainframe stuff has better job control, but I don't have experience with mainframes.

      --
    9. Re:perl by goombah99 · · Score: 2, Informative

      If all you're doing is moving files around or creating tarballs etc. then all those backticks in perl can become a PITA

      it's easy to wrap shell into perl when one feels the backtick are getting in the way. To be pendantic:

      <perl commands go here >

      system <<EOC; # the bash script follows
      echo "embedded bash script begins"
      ls /tmp
      tar -xc fooberries.tar /tmp
      mv tweedlee.txt tweedeldum.txt
      echo "bash script done, now resuming perl interpreter"
      EOC

      <further perl commands here.>

      --
      Some drink at the fountain of knowledge. Others just gargle.
    10. Re:perl by ceswiedler · · Score: 3, Interesting

      Are you saying people should use Perl as an interactive shell? Or are you saying people should never use bash non-interactively?

      The entire concept behind 'shell scripting' is to make it easy to tie together the same commands you type into the interactive shell. When I get used to doing 'rm' and 'cp' I can write an easy shell script which does the two together.

      Of course, once you get to large shell scripts, then it becomes much more sane to use a real language rather than a shell script.

    11. Re:perl by Anonymous Coward · · Score: 0

      lately? I've never installed anything *nix that did not have perl in the last 15 years.

    12. Re:perl by dannycim · · Score: 1

      I've run out of fingers and toes trying to count the number of inefficient perl scripts I've replaced with much faster and simpler shell scripts. Bad code can be written in any language.

    13. Re:perl by takshaka · · Score: 1

      Backticks? Why on earth would you use backticks to move files around? That's what File::Copy is for. And Archive::Tar handles tarballs.

      Write Perl code, not shell scripts wrapped in Perl code.

    14. Re:perl by frenchbedroom · · Score: 2, Informative

      Bash is also a command line interpreter. This allows you to try out stuff before writing a script, which you can also do in the same environment : just use cat.

      Just try this :
      $ perl
      ls

      What ? No output ? :)

    15. Re:perl by Anonymous Coward · · Score: 0

      No I'm not trolling...

      Mod this WAY up for knowing that troll is a verb, not a little guy under a bridge!!

    16. Re:perl by mevets · · Score: 1

      I've never fully understood why perl is around. Not bashing (mind the pun), but it seems to bring nothing to the sh/awk/sed/... table, but fills all the closets with junk, and lays version incompatibility traps in the hallways. I swear that the infamous Gates memo ( about trying to get some application ) could be modified (using sed, of course) to be about perl, and everyone would nod their head in agreement. The idea is to make things simple, so you have a chance of making them work at all.

    17. Re:perl by Ex-Linux-Fanboy · · Score: 2, Insightful

      I've never fully understood why bash is used anymore when perl is around

      The right tool for the right job. For example, I've been using sh/bash for a bunch of SQA regression tests for a command-line caching DNS server I'm working on (my current open-source project). Here is one of the simpler tests so you can get an idea of the syntax:

      for VALUE in 0 1 ; do

      cat > dwood2rc << EOF
      chroot_dir="$( pwd )"
      ipv4_bind_addresses="127.0.0.1"
      upstream_servers["."]="127.0.0.2"
      recursive_acl="127.0.0.1/16"
      maxprocs=8
      timeout_seconds=1
      handle_noreply=${VALUE}
      EOF

      ../../src/DwMain -f dwood2rc > /dev/null &
      sleep 1
      echo handle_noreply=$VALUE
      askmara -t 8 Awww.example.com.
      sleep 1
      killall DwMain > /dev/null 2>&1
      sleep 1

      done

      Now, yes, one could do a test like this in Perl, but all we're really doing is making a file with some parameters we're testing, then running the program being tested with those parameters. Here, DwMain is the DNS server I'm testing and askmara is like dig, but simpler.

      I used to be a big-time Perl scripter, but I feel it's usually too big and complicated for the tasks I'm doing.

      For embedded systems, keep in mind the Perl core library is well over a megabyte in size; a full *NIX system in busybox (with sh, awk, ls, and pretty much any other command you would type at the command line) is only about 500k in size. This matters in things like routers and mini-Linux distributions (I once made a Linux distribution that was under 30 megs in size that included a GUI and the Firefox web browser).

      Also, the thing that annoys me with Perl is that there is no standard that defines how Perl should act; the only standard is the Perl interpreter itself, and this has changed in strange ways that sometimes makes debugging Perl scripts difficult. What guarantee is there that my Perl scripts will run in Perl 6 or what not?

      Also, when people add a lot of stuff from CPAN, Perl starts getting in to "dll hell"

      sh, on the other hand, has its behavior defined by POSIX, and if I make a POSIX-compliant script, there's a pretty good chance it will continue to run for the foreseeable future.

    18. Re:perl by harry666t · · Score: 1

      That's great. I've always wanted to really learn Perl, and I recently started to, so as an exercise, I wrote a Perl program that could automatically translate all my shell scripts to Perl:

      #!/usr/bin/perl
      use strict;
      use warnings;
      print "#!/usr/bin/perl\nsystem<<EOC;\n";
      print foreach(<>);
      print "EOC\n";

      Man, I rock.

    19. Re:perl by Anonymous Coward · · Score: 0

      You know, there are built-in functions and modules that do that stuff, too.

      Functions for filehandles, files, or directories
                            "-X", "chdir", "chmod", "chown", "chroot", "fcntl", "glob",
                            "ioctl", "link", "lstat", "mkdir", "open", "opendir", "readlink",
                            "rename", "rmdir", "stat", "symlink", "sysopen", "umask", "unlink",
                            "utime"

      $perldoc perlmodlib
       
            Archive::Tar
                        Module for manipulations of tar archives
            File::Copy Copy [or move] files or filehandles
            IO::Compress::Gzip
                        Write RFC 1952 files/buffers

      No need for backticks. Also, your script will be more portable. More windows machines have a perl interpreter than a bash shell.

    20. Re:perl by deKernel · · Score: 1

      Perl comes into play when the shear volume and complexity of the tasks increase. If you are processing a few files, sed/awk and such are fine.
      Now image if you had to process several hundred files (forking for awk/sed/grep now comes into play for several hundred times).
      Now image you had to say add some of that data into a database for post processing? Now you have a fork for each call into say MySql command utility.
      Now image you needed to send that data to another machine via a socket? And say you had to reformat that data into..oh say...XML.

      See where this is going? Think of Perl as a shell on 'roids.

    21. Re:perl by goombah99 · · Score: 2, Insightful

      Okay now suppose you wanted to perhaps have an exception test for the killall or the askmara. Or suppose you wanted to have a time-out if they never returned. Finally assume you wanted to log the result of the action. Maybe you want to use a command line variable to supply say a password and the number of retries.

      Yes you could do all that in shell script. it simply is easier in perl.

      your assurance that your perlscripts will run is that the first line of the perl program specifies which perl interpreter to use. if it requires 5.6 you tell it to use 5.6

      --
      Some drink at the fountain of knowledge. Others just gargle.
    22. Re:perl by smoker2 · · Score: 1

      Perl is for CGI and private scripts separately. I would never give the shell power from the net. But I'm happy to run perl as CGI and bash from 0:1. I never mix the two. But you can pick on PHP if you want to get nasty about it. There is a perl shell available, but you need to know perl to use it properly. That's probably an obstacle to you, so yet another year without the Desktop crown then !

    23. Re:perl by smoker2 · · Score: 1

      So you're calling perl with no arguments, inside another shell ?

      Nice.

    24. Re:perl by smoker2 · · Score: 1

      Not if you know perl. I don't know C# either, but that doesn't matter for what I'm doing.

    25. Re:perl by anothy · · Score: 1

      amen, brother, amen.

      --

      i speak for myself and those who like what i say.
    26. Re:perl by anothy · · Score: 1

      perl exactly falls apart when the complexity of the task increases. the language is a mess. i mean, really: compared to most anything out there, it's a hideous mess. the average quality of perl code i've seen is substantially below any language except VB and friends. one can write reasonable perl code, sure - i work with a guy who does a pretty good job - but it's very hard. and that's true both in the sense that there's a strong temptation to write poor code, given the dozens of ways to do everything, and in the sense that being clear in the language slows you down more than being clear in a more properly-structured language.

      your biggest concern is fork? really? if it's that bad, you need to get on a more reasonable platform (or try, say, using statically-linked binaries). but being able to hand off tasks to tools designed for them is a huge benefit. you think making socket connections in perl is a reasonable thing to do? oh, lord.

      i find it very telling that your big comparison is bash, perhaps the most bloated shell available. if you want a nice, simple, clean, and clear shell, try rc. if the complexity really is as dramatic as you say, and the speed is as important as you imply, you want to be writing in a systems language. try C.

      you say i should think of perl as a shell on steroids. if by that you mean it's got a heart problem, looks ridiculous, tends to be overly aggressive, grows out of proportion to utility, and increases depression and suicide, okay, i'll give it to you.

      --

      i speak for myself and those who like what i say.
    27. Re:perl by anothy · · Score: 1

      for example, let's say the ease of use of scripting means that until a program runs longer than, say, ten minutes to do a job you will prefer script over compiled lnaguages. the equivalent bash program if it does any serious parsing might take 3 hours. This is why one might still use a script language even when "speed" is an issue.

      what a stupid non-example. not only is there no example in your example, but there's so many other things wrong with it i don't even know where to start.

      first, you've picked a totally arbitrary number for the scripting/compiled schism. how exactly did you come up with that? and is it really true in all cases? what're the constraints?
      and, of course, the dichotomy is largely false. with on-the-fly compilers (not to mention the old fashioned kind that just apply to new languages), many "scripting languages" are compiled languages. is Java faster because it's compiled? faster than what? for what tasks?
      i don't know much about bash's internals, but several shells actually include on-the-fly compilers for their input. so, again, i'm curious if you've actually measured anything, or are just talking out your rear.
      how the heck are you structuring these shell programs that you have enough fork calls to make things 1000x slower? grep certainly isn't going to slow you down itself, nor is awk (i'd be a little surprised if it wasn't the opposite, actually). i've read entire lp systems written in shell scripts that don't have that many forks.
      and when writing in shell scripts, the shell itself is, for the most part, glue; most of the work happens in other programs (things like sed, awk, and so on), as you note. all of which, of course, are compiled in pretty much every environment.
      but i guess, sure, you could construct an example where it "might take 3 hours". or it might take 3 minutes. show me some examples. show me the results of your timing trials. otherwise i'll just counter with "perl takes ten times longer to write than rc, runs half as fast, and the average bug count is twice as high". see? i can make up numbers, too.

      shell script is preferable to perl because it's easier to read, easier to write reasonably, and has a low overhead cost. your "1000 times slower" number is a figment of your imagination.

      --

      i speak for myself and those who like what i say.
    28. Re:perl by goombah99 · · Score: 1

      Despite your discourtesy here is a response.

      shell script is preferable to perl because it's easier to read, easier to write reasonably, and has a low overhead cost. your "1000 times slower" number is a figment of your imagination.

      Write a loop that iterates over 100000 short files. for each file run an awk script, a sed script on the result and a grep.

      See you tommorrow.

      or you could use perl and have it done in ten minutes.

      --
      Some drink at the fountain of knowledge. Others just gargle.
    29. Re:perl by Ex-Linux-Fanboy · · Score: 1

      OK, don't get me wrong. I used to be a professional Perl programmer and think Perl is useful for a lot of things. The most recent time I made significant use of the "Swiss army chainsaw" is to write a program to split up the large .html files one gets from free ebooks over at baen.com and make them small enough to be usable with my cell phone's built-in html reader:

      http://maradns.blogspot.com/2008/11/more-on-nokia-5310-xpressmusic.html

      I also still use Perl as a "sed on steroids" when I can't be buggered to figure out how to make a given regex Perl-compatible, such as this real-world example:

      perl -pe 's/[0-9]+\/DwMain//;s/\s*//g'

      I also have had the privilege of meeting and having dinner with Larry Wall; a very kind person with a very deep and strong faith in God which I respect.

      The issue I have with Perl is that it's too big to use in the really embedded space that busybox really thrives in, and is too big to, say, come with the version of MSYS I use. (MSYS is a subset of *NIX for Windows systems that I use when I want the basics of *NIX on a client's Windows machine but don't want to waste time putting Cygwin on their system). My other issue is that Perl code can more easily become unmaintainable "spaghetti code" if there isn't a strong coding style in place and enforced; these days I prefer to use Python when I know a given script is going to be pretty big. Also, Perl's big use when I was a professional Perl programmer, being an excellent cgi-bin language, has by and large been superseded by PHP these days. [1] [2]

      Anyway, I don't hate Perl. I still use it; I just feel these days for small stuff sh/awk/sed/etc. make more sense, PHP makes more sense for web monkey applications, and Python (or Java) make more sense for big scripting projects.

      [1] Back when I was a Perl pro, I used it mainly for things like data mining and email processing, but that's neither here or there and from a long time ago.

      [2] There is, of course, mod-perl, used very notably by Slashdot. There's also mod-python.

    30. Re:perl by anothy · · Score: 1
      what the hell, i'm bored.

      well, i didn't see your message until just after midnight, so i guess it's technically tomorrow. certainly didn't take a day. this is the first thing i came up with which satisfied your requirements; it actually does much more than the minimum work to satisfy that, but this was what i thought of first. it took less than five minutes to write, about one minute of which was because i forgot awk's NF isn't addressed as $NF, and about one was because i kept typing "sed" when i meant "seq".

      this OS X box is working in an external firewire disk. i don't happen to have 100,000 small files lying around to poke at, so i started by creating them, in a hugely seek-heavy way. typing this now, i realize i should've scripted my editor to dump segments; oh, well. as expected, the seeks on disk I/O made the creation step take a long time. regardless, the code is nice and easy to read, very straight-forward. each tool does just its job, and the shell puts things together nicely.

      : Yud; pwd
      /Volumes/Twin/sandbox
      : Yud; ls
      : Yud; date
      Fri Mar 6 00:09:53 EST 2009
      : Yud; for (i in `{seq 1 100000}) {sed $i^q /usr/share/dict/words | tail -10 > $i}
      : Yud; date
      Fri Mar 6 00:52:39 EST 2009
      : Yud; >/tmp/youarea
      : Yud; start=`{9 date -n}
      : Yud; for (i in *) {
      echo $i:
      echo -n '5-letter words:' ; grep '^.....$' $i | wc -l
      echo -n 'fake multi-words:' ; awk 'BEGIN {FS="k"}; NF==2' $i | wc -l
      if (grep -q dick $i)
      echo dick!
      }>> /tmp/youarea
      : Yud; stop=`{9 date -n}
      : Yud; wc -l /tmp/youarea
      300020 /tmp/youarea
      : Yud; echo $stop - $start | hoc
      2357

      that's a bit under 45 minutes to generate all the files, and a bit less than that again to process them, from my firewire 400 disk. how much of that do you think was fork? my money says disk I/O dominates; perl will do zero for you there.

      were i doing this for more than a throw-away project, there's a number of obvious optimizations, like loading at least the words file into RAM up front, which would improve performance, too. but these times aren't too bad. it'd be interesting to know how much of it was disk-bound, too; i suspect a good bit.

      i don't write perl for the same reason i don't eat moldy bread (if i had to i might, but if there's anything better around, i'll do that instead), but if you'd like to provide a perl program that does the same thing, i'd be happy to benchmark it for you. you're aiming at 1/1000th the time. that gives you about 2.7 seconds to do the file creation and 2.4 seconds to do the processing. good luck. let me know when you haver perl code for me to try that comes with an order of magnitude of your target.

      and perhaps i'm being discourteous, but your presumption and ignorance was overwhelming. you need educating.

      --

      i speak for myself and those who like what i say.
    31. Re:perl by SL+Baur · · Score: 1

      I've never fully understood why bash is used anymore when perl is around.

      I think it's dumb writing bash scripts instead of portable scripts (or worse, /bin/sh scripts and expecting to get bash), but anyway ...

      Use the right language for the task at hand. Sometimes perl doesn't make sense. I'm about to kill a number of perl scripts that I'm currently supporting that are written in (bad) perl that can be replaced with one-liner find ... -exec ... commands.

      There are plenty of things that can be done via the shell that are way more awkward to do in perl. No language is perfect.

    32. Re:perl by RichiH · · Score: 1

      > When I get used to doing 'rm' and 'cp' I can write an easy shell script which does the two together.

      And then call it mv? ;)

    33. Re:perl by SL+Baur · · Score: 1

      if you are parsing text or doing any sort of complicated extractions you have to repeatedly use grep awk and sed in bash to accomplish the job.

      You haven't explored modern shell syntax very much. See the links in articles I posted above which point at BASIC Interpreters and Adventure games being written in basic, Steven Bourne, /bin/sh.

      But ... extensions sanctioned by ksh and later bash/zsh (POSIX standard now), go much further.

      I saw the Shell BASIC interpreter fly by on Usenet when it was posted and since I had access to ksh, I rewrote my own version with ksh. It utilized the line editing library to allow line editing in the BASIC command line, had single step, trace and interrupt debugging and utilized ed(1) as a coprocess to store the program buffer and a custom tiny yacc-based floating point expression program to perform numeric calculations. Took all of a few days to write from scratch.

      Personally[1], I would consider zsh scripts easier to do than anything else, if its just speed of development you're looking at.

      [1] Who needs perl when you have xemacs -batch?

    34. Re:perl by deKernel · · Score: 1

      perl exactly falls apart when the complexity of the task increases. the language is a mess. i mean, really: compared to most anything out there, it's a hideous mess. the average quality of perl code i've seen is substantially below any language except VB and friends. one can write reasonable perl code, sure - i work with a guy who does a pretty good job - but it's very hard. and that's true both in the sense that there's a strong temptation to write poor code, given the dozens of ways to do everything, and in the sense that being clear in the language slows you down more than being clear in a more properly-structured language.

      Just about all languages can be abused if so desired. Don't get me wrong, I am not that big of a Perl fan, but it does have its place, and I feel this is one of them.

      your biggest concern is fork? really? if it's that bad, you need to get on a more reasonable platform (or try, say, using statically-linked binaries). but being able to hand off tasks to tools designed for them is a huge benefit. you think making socket connections in perl is a reasonable thing to do? oh, lord.

      The issues of fork are not the only issue. It is just one of a few. I guess I should have made that clear in the beginning. You mention getting statically linked binaries so now I need have special binaries to run my scripting actions when all I need is just Perl installed. Granted, the socket implementation in Perl is not the best, but I have code that I use over and over that helps speed up development time.

      i find it very telling that your big comparison is bash, perhaps the most bloated shell available. if you want a nice, simple, clean, and clear shell, try rc. if the complexity really is as dramatic as you say, and the speed is as important as you imply, you want to be writing in a systems language. try C.

      I used bash because of the ability to run in Bourne-mode which gives the same abilities across most/all OS's (kinda like what Perl gives me: OS independence other than file system...grrrr Windows). I live and breath in C/C++ so writing a app to do what I need would not be an issue, just a real pain in the arse constantly changing the code to make a small change to say file location or name (Yes, I could have an config file that I use for this, but now I am getting darn close to just creating a new shell). That is what scriptiong is for: quick and dirty.

      you say i should think of perl as a shell on steroids. if by that you mean it's got a heart problem, looks ridiculous, tends to be overly aggressive, grows out of proportion to utility, and increases depression and suicide, okay, i'll give it to you.

      Each of your points are valid, but now I am cobbling together many things to get the overall results that I feel I get in a one-stop-shopping of Perl. I guess you could replace Perl with Python if that make you happy.

    35. Re:perl by goombah99 · · Score: 1

      And don't get me wrong. Bash has it's uses. Space efficiency is important as you point out. And in my original post I said I was talking about scripting not interactivity. Bash is more convenient for interactivity as well.

      My point was I don't see why bash persists in scripts.

      --
      Some drink at the fountain of knowledge. Others just gargle.
    36. Re:perl by anothy · · Score: 1

      no, that wouldn't make me happy. ;-)

      the fork thing is just a red herring; that was suggested only as one method of optimization if fork really were a big problem. i didn't believe it was, so the suggestion is really irrellevent.

      it is true that perl can be used in such a way that you get better "out of the box" portability with your applications with fewer dependencies. but even in the cases where that's relevent, it's a rare perl program of any size that'll do that. just removing the availability of the backtick operator lops off a bunch.

      you're certainly right that any language can be abused, but some lend themselves to it more than others. perl begs for it.

      --

      i speak for myself and those who like what i say.
    37. Re:perl by sjames · · Score: 1

      In part, because you can be absolutely sure that if the system can be used interactively at all, it has a shell. If it doesn't have a shell, you probably have no way to fire off a perl script. Perl may or may not be installed.

      Shell script is natural for file manipulation and executing programs. Perl is natural for extracting data and producing a report :-)

    38. Re:perl by badkarmadayaccount · · Score: 1

      You do realize that PHP's got more FAIL than Perl, COBOL and Befunge combined? Not that I'm bashing web developers or something, but technical superiority lies within Perl, period, as far as my experience is concerned
      (meaning the number of (please note:(I'm getting real LISP-y with this, ain't I?))technical bashing posts (on /.) about PHP far exceeds the number of such posts about Perl).

      --
      I know tobacco is bad for you, so I smoke weed with crack.
  11. Quote: by Anonymous Coward · · Score: 0

    bash is hard, let's go shopping!

  12. Do windows users need a shell? by Savage-Rabbit · · Score: 4, Insightful

    Because most Windows users need a shell. Right.

    I think the original comment was directed at Windows Server users not Windows consumer desktop users (unless the user of that consumer desktop is a developer or an admin). I'll agree that most consumer desktop users don't need a shell. I may be a developer these days but I have been an administrator for Linux, Solaris, AIX, several lesser known incarnations of *NIX, Windows NT, Windows 2000 Server and Windows 2003. I can tell you that there are times when you really miss the command-line power of the Unix shell on Windows servers. There are tasks you simply can't do on a Windows server except through the GUI which is nice if you don't have to do it often but when you have, say... a project where you have to do the same set of tasks a few thousand times in a row and want to complete this project in a sane amount of time scripting is a must. The only alternative for solving some such problems even on Windows 2003 is to write a C# program because you can't solve the problem by scripting. Writing a C# program is something I wouldn't expect an average Windows admin to be able to do anymore than I require a Unix admin to be a seasoned Java developer. IMHO an average Windows Server admin or Unix admin should be seasoned at scripting but I wouldn't expect either to be seasoned at C# or Java programming, VB or Perl would be good though. I am not prepared to take a server OS seriously unless I can do more on it's command-line than I can do with the slick GUI management tools.

    --
    Only to idiots, are orders laws.
    -- Henning von Tresckow
    1. Re:Do windows users need a shell? by TheLink · · Score: 5, Interesting

      You can use perl and python for windows.

      For example, for perl there's Bundle::Win32

      http://search.cpan.org/~jdb/Bundle-libwin32-0.30/libwin32.pm

      Useful stuff like: Win32::TieRegistry , Win32::ChangeNotify

      But be good and don't write malware. The antivirus people might give up trying to detect perl malware (think about it - polymorphic TMTDOWTDI perl malware...), they might just flag/blacklist perl itself :).

      --
    2. Re:Do windows users need a shell? by CannonballHead · · Score: 1

      Hence, me stating the following?

      Arguably, it would be nice on the server side, I guess... but Windows did appear to try to get AWAY from the command line.

      I guess it's not even fashionable on slashdot to read the comment you are replying to ;) hehe.

      I admit, shells and command-lines are pretty nice. If I want to know the IP of my windows box I do ipconfig, not double click the network connection.

      But most people aren't running Windows Server. Most people are running Windows XP, Vista, whatever. They don't need a shell for most things... and, as someone replied to you, you can use python and perl on Windows. And there's always batch scripts ;) (blech. I've written them, wicked things.)

    3. Re:Do windows users need a shell? by Haelyn · · Score: 1

      polymorphic TMTDOWTDI perl malware...

      ...I think you repeated yourself...

    4. Re:Do windows users need a shell? by RAMMS+EIN · · Score: 2, Informative

      The question, though, is why C# or Java "programming" is so different from "scripting" that you'd expect a sysadmin to know the latter, but not the former.

      --
      Please correct me if I got my facts wrong.
    5. Re:Do windows users need a shell? by RAMMS+EIN · · Score: 1

      Does Windows seriously not come with any way to automate things? I mean, besides batch scripts, which, unless I'm mistaken, allow you to do some of the things you could do under DOS, but that don't actually interface to what you would normally work with under Windows much.

      --
      Please correct me if I got my facts wrong.
    6. Re:Do windows users need a shell? by Savage-Rabbit · · Score: 1

      I guess it's not even fashionable on slashdot to read the comment you are replying to ;) hehe.

      You said it would be 'nice' which implies you could live without it, even on the server side. I was trying to make the point that a powerful shell on a server or scripting ability for an admin is not optional it is required. :-)

      --
      Only to idiots, are orders laws.
      -- Henning von Tresckow
    7. Re:Do windows users need a shell? by Nick+Number · · Score: 1

      Every version since Win98 has included the Windows Script Host by default. This allows one to automate quite a variety of tasks out of the box using vbscript or javascript. It's a little clunky for some things (e.g. recursive file searches), but is generally flexible enough for most needs.

      --
      Promote proofreading. Don't mod up sloppy posts.
    8. Re:Do windows users need a shell? by CannonballHead · · Score: 1

      I suppose it depends on what the admin is doing. Running a simple web server or something like that doesn't require a ton of shell power, in my experience...

      That said, point taken. I think ther'es a reason Linux/UNIX is way more popular on the server side than it is on the home consumer side.. :)

    9. Re:Do windows users need a shell? by nuckfuts · · Score: 1

      Bah. Every version of Windows I've used has a command shell. Even when the available commands were basically equivalent to MS-DOS, it was possible to do almost anything via a .BAT file. One can pass variables, prompt for input, do conditional branching, loops, even create and call new batch files dynamically.

      I personally enjoy the challenge of writing .BAT files that rely soley on native commands. As far back as Windows 95 I've written .BAT files that could: Run automatically on a per computer OR per user basis. Self-modify the conditions for running and log results. Perform updates, remove viruses, edit the Registry and more.

      Using such techniques, I was able to automate updates on hundreds of Windows machines at a time before "Windows Update" even existed. So, yes, a Windows shell is useful. PowerShell merely enriches the scripting capabilities.

    10. Re:Do windows users need a shell? by afidel · · Score: 1

      Windows has the following standard options for scripting:
      vbscript, jscript, batch, and on most 2008 boxes powershell.
      Optional:
      perlscript

      Also there are quite a few third party scripting engines available. There are a TON of things you can do on the command line that you can't do in the GUI including almost all AD debugging. I write batch files every week and vbscripts probably at least monthly. I can't wait until powershell supports remote objects so that it becomes more useful in a networked environment.

      --
      There are 4 boxes to use in the defense of liberty: soap, ballot, jury, ammo. Use in that order. Starting now.
    11. Re:Do windows users need a shell? by turgid · · Score: 1

      I'd hazard a guess that, since scripting languages rely heavily on external commands compared to conventional languages, you'd expect a sysadmin to be better at scripting than a straight-forward developer.

      This assumes a lot though, that the developer is a corporate straight-jacket Microsoft IDE coder (who never sees a command line) and that the sys admin is a command-line whizz.

      These days, what with most people knowing at least some Linux (or other Unix) the line is getting blurred between the too. Many admins who only knew Windows are learning Linux and many coders who were stuck in Visual Studio hell are too.

      Conversely, some of us Linux types who have avoided Windows since '95 came out, are having to learn a bit of Visual Studio to port away legacy code to Linux/Solaris.

    12. Re:Do windows users need a shell? by Spit · · Score: 1

      Cygwin makes windows bearable.

      --
      POKE 36879,8
    13. Re:Do windows users need a shell? by fractoid · · Score: 1

      The question, though, is why C# or Java "programming" is so different from "scripting" that you'd expect a sysadmin to know the latter, but not the former.

      It's not that it's "so different", just that they're different specialised domains of "programming". It's no different from expecting, say, a scientist doing number crunching to know FORTRAN and MatLab but not DirectX. Or expecting a hardware driver engineer to know how to work with the WDM but not how to validate a field in an MS Access form.

      --
      Rampant carbon sequestration destroyed the Dinosaurs' tropical paradise. I'm here to help repair the damage.
    14. Re:Do windows users need a shell? by fractoid · · Score: 1

      I dunno what version you're using to say that working with Visual Studio is hellish. I've just switched jobs to a place that uses Borland C++ Builder... maybe it's partly familiarity but VS2005 is, IMO, leaps and bound ahead in usability.

      --
      Rampant carbon sequestration destroyed the Dinosaurs' tropical paradise. I'm here to help repair the damage.
    15. Re:Do windows users need a shell? by gnu-user · · Score: 1

      WSH/vbscript is a fine thing. It let me feel somewhat at home in the last job I had with strong windows server work.

      That said, it has an extremely important weakness, no way to implement recursive libraries. For one offs, it's just fine, but for anything more complex, the P's are a much better choice.

      I did come across a complete hackish way to implement this, read the library in and interpret it. That's a pretty dangerous substitute for having real library support.

      For what it's worth, the IIS vbscript does not have that weakness. It does allow libraries to call libraries.

    16. Re:Do windows users need a shell? by turgid · · Score: 1

      After working with Linux and Solaris for 12+ years, having to use Visual Studio is hellish.

    17. Re:Do windows users need a shell? by fat_mike · · Score: 1

      Really?

      I have a co-worker who has a daughter that's a Limewire/Facebook/Myspace junkie. Her computer was completely smoked to the point where the only things that worked were the spyware/malware apps. I was able to get Windows telnet server started on it and go in and clean it up from the shell.

      I write backup scripts in the Windows shell using old school DOS tricks. Its a hell of a lot faster than writing it in VB or C and doesn't require my users to have to do anything other than double-click the icon.

      Anybody here ever use Bart's Boot Disks? Take a look at the genius of some the batch files used.

    18. Re:Do windows users need a shell? by sjames · · Score: 1

      In part, it's because shell scripting is more friendly to being fired off interactively on one line like a command, and has simple variable substitutions.

      While I don't do C#, java will at least need a bit of syntactic sugar just to get started.

      Shell script can be as simple as a log of commands you would otherwise enter one at a time and can gracefully evolve into a full blown program. A Unix admin will already be quite familliar with the command line, he just has to add variable substitution and a basic knowledge of the flow control structures, and POOF, he knows scripting well enough for it to be useful.

  13. Compiler research by TinBromide · · Score: 2, Interesting

    I'm always amazed when I read about research into compilers and whatnot. Once upon a time, building computers weren't just a matter of arranging a series of blocks into a procedure and hoping if you OR'd 2 numbers, you'd get the right one out or applying Algorithm A to Problem B and getting optimal solution C.

    I wonder if the bell labs researchers got the eureka moments when their applied research in compilers worked like the CERN physicists detect a theoretical particle.

    --
    Is it sad that I am more likely to recognize you and your posts by your sig than your name or UID?
  14. what was that shell game... by Anonymous Coward · · Score: 0

    you don't know jack sh

  15. Re:PowerShell is *NOT* for powerusers. by Anonymous Coward · · Score: 0

    You don't need a shell? Presumably because you don't understand the power of it.

    I have bash scripts for:
    - slowly decreasing the speakers volume when I go to bed.
    - Managing laptop events (if I'm at home, don't call screensaver lock when I close the lid - for example).
    - Do whatever people usually do with Matlab (YES, imagemagick + bash + gnuplot + octave)
    - Re-encode and normalize my ogg music collection.
    - Managing firewall rules when I enter home and university automatically.
    - Grab and parse data from www (using wget) for feeding my little spiders.
    - Create a secure VPN, route all traffic to there and drop packages *NOT* going to the default route.

    These are the ones that I have currently active and could remember.

    Seriously.. I see university colleagues spending hours doing format conversion between text files by *HAND*. Things that you can simply do by writing a few bash + binutils lines.

    Ir seeing teachers copy-pasting stuff from the internet by *hand* to a spreadsheet whenyou can simply parse the HTML for it and feed a cvs file.

    So. if people don't need bash that's because either they don't know the power of it or they clearly are not power users. There is also the third option, they are masochists.

  16. Re:PowerShell is *NOT* for powerusers. by CannonballHead · · Score: 1

    FWIW, I'm a software tester and regularly script in perl, bash, python, and a lot of xml stuff as well. The products that I test were primarily command-line products, and I'm involved in automating testing of that side of the product, hence the scripting. But thanks for assuming ignorance ;)

  17. Its disapointing that he knows so little of Bash by Anonymous Coward · · Score: 0

    Bash is not just an open source sh.

    Bash adds all the features of ksh and some more.

  18. This inspired me to write a tiny *NIX shell by Ex-Linux-Fanboy · · Score: 2, Interesting

    I saw this article on OSnews this morning, and it inspired me to write a tiny open-source (public domain) *NIX shell, which can be seen at http://www.samiam.org/software/yash.html. I know the busybox guys are looking to rewrite their *NIX shell to be more modular; this code would be a good starting point.

    - Sam

    1. Re:This inspired me to write a tiny *NIX shell by larry+bagina · · Score: 1

      tip: feof() lets you know if it's the, well, eof.

      --
      Do you even lift?

      These aren't the 'roids you're looking for.

  19. Now there's a man with hair on his chest by TennesseeVic · · Score: 5, Funny

    He was writing an _Algol68_ compiler as part of his Ph.D. work in _astronomy_?! I'm not worthy! I'm not worthy!

    1. Re:Now there's a man with hair on his chest by garyebickford · · Score: 4, Insightful

      And this speaks to why IMHO it was unfair (besides being stupid) to change the rules on software patents in 1986. Prior to that time, the huge amount of seminal, fundamental, wonderful work (by geniuses and people much smarter than me) in software and systems could not be patented, so it was either secret (for a while) or open. All those giants back then had no opportunity to set up a licensing toll bridge. And now, an infinite regression of trivialities are patented.

      Imagine what progress in computing would have been if Alan Kay had been able to patent windowing GUIs, or if object-oriented programming had been patented, or paged virtual memory, timesharing, CDMA, TCP, IP, programming macros, relocatable code linkers, electronic mail, image morphing, most computer graphics and imaging techniques, ... the list goes on.

      Some of the core ideas incorporated by Berners-Lee in his WWW creation could have been patented either by him, or by NeXT Computer before he had a chance. And then where would we be?

      Hell, I personally could have gotten patents on client-server image processing nets, steganography, SAN, image paging and pre-fetch, pan-and-zoom image and map display, a whole raft of specialize raster-op (bitblit) functions, physical mapping of image files onto disk sectors, street-address interpolation, for geolocation. And that's just a sample of the bigger stuff I was involved in from 1983-1985. Oh yeah - a collaborative sketchpad over ethernet, in 1982!

      At the time (early and mid 1980's) NONE of this was patentable. And now people are getting held up for $millions for stuff we didn't even bother to document or publish, because it was so trivial. And (just for perspective) I was just a regular schmoe - not one of the lights of programming.

      rant, rant, rant... I totally agree with what you said :) I was not and am not worthy either. And certainly neither are the market- and legal-droid twits at Amazon and Microsoft and elsewhere who browbeat the software writers into signing off on the post-placental detritus that modern software patents are and will always be.

      --
      It's easier to be a result of the past, but more fun to be a cause of the future! http://www.spacefinancegroup.com/
    2. Re:Now there's a man with hair on his chest by martin-boundary · · Score: 1

      He was writing an _Algol68_ compiler as part of his Ph.D. work in _astronomy_?! I'm not worthy! I'm not worthy!

      And let's not forget, that's in addition to being a secret agent who one time lost his memory!

    3. Re:Now there's a man with hair on his chest by Anonymous Coward · · Score: 0

      Amazing. Thanks.

    4. Re:Now there's a man with hair on his chest by sjames · · Score: 1

      My first supercomputer was a collection of DOS machines with Lantastic cards using mailbox files for IPC. It worked quite well for problems where the parallelism could be sufficiently coarse.

      These days, Amazon would like to believe that the equivalent of writing the customer's name, address, and credit card number down on an index card so they can just say put it on my card is worthy of a patent.

    5. Re:Now there's a man with hair on his chest by garyebickford · · Score: 1

      These days, Amazon would like to believe that the equivalent of writing the customer's name, address, and credit card number down on an index card so they can just say put it on my card is worthy of a patent.

      So true! Like the grocers of old - "Just put it on my tab, Bill."

      --
      It's easier to be a result of the past, but more fun to be a cause of the future! http://www.spacefinancegroup.com/
  20. Windows Script Host by tepples · · Score: 2, Informative

    Does Windows seriously not come with any way to automate things?

    Windows Script Host allows a program written in JScript or VBScript to control any app that exposes APIs through OLE Automation.

  21. C# and Java vs. the "P" languages by tepples · · Score: 3, Insightful

    The question, though, is why C# or Java "programming" is so different from "scripting" that you'd expect a sysadmin to know the latter, but not the former.

    Perhaps because the syntactic salt of C# and Java makes them cumbersome than the "P" languages for the sorts of automation tasks that sysadmins handle routinely:

    • The developer must compile a program explicitly, unlike the "P" languages that automatically call the compiler to produce bytecode.
    • The developer must define explicitly what class a particular translation unit represents, compared to Python where each file implicitly describes a module.
    • C# and Java use named interfaces instead of the typical duck-typing approach of Python where any object that implements a given set of methods will work.

    Not to mention that a lot of sysadmins learn some of their languages through hobby projects on shared web hosting, and more shared web hosting environments have "P" languages than ASP.NET and Java servlets.

  22. The Unix Shell and Scripting Languages by Tetsujin · · Score: 3, Interesting

    Backticks? Why on earth would you use backticks to move files around? That's what File::Copy is for. And Archive::Tar handles tarballs.

    Write Perl code, not shell scripts wrapped in Perl code.

    All of this raises an issue that interests me, with regard to the shell and scripting languages...

    The shell is supposed to be a convenient interface for accessing the functionality your system has to offer - but because of the way that functionality is offered it's hard to take advantage of it. The shell hasn't got much in the way of support for datatypes, namespaces, and so on. This makes it a lot easier (and, often, more efficient) to program in a scripting language like Perl or Python, and implement all kinds of useful functionality as libraries for that language, instead of as shell programs.

    So scripting languages have the advantage of providing a much more structured and full-featured programming environment - a better foundation on which to build more complicated programs and more sophisticated tools. But the whole thing is one degree separated from the normal interaction with the shell - it's not trivial to expose all that functionality implemented for the scripting language to code outside the scripting language... The scripting language becomes a rich environment all its own, but that functionality isn't part of the shell environment, because the shell environment doesn't support the organizational concepts that make that code manageable within the framework of the scripting language.

    I feel like this situation is a problem - I believe in what some people call "The Unix Way" - chaining together small tools to do bigger jobs, but the shell doesn't have the organizational constructs to make this work for complex problems - and as a result people are doing this great work on adding functionality to the system, but it's getting packaged up as scripting language modules since the shell can't handle it. It's something I'd really like to correct.

    --
    Bow-ties are cool.
    1. Re:The Unix Shell and Scripting Languages by goombah99 · · Score: 1

      The original point of perl is to address your concerns. You want to be close the machine (in the unix not the C sense) but you want enough high level functionality. And you want to chain stuff.

      Perl is the ultimate glue language. it's not so lovely as python or ruby but it's much more adapted for glueing and staying as close to shell scripting as possible. At the same time it has nice libraries that mean it can do so much more if you need to go there.

      --
      Some drink at the fountain of knowledge. Others just gargle.
    2. Re:The Unix Shell and Scripting Languages by Tetsujin · · Score: 1

      The original point of perl is to address your concerns.

      But it's not a shell, and frankly I don't want it to be my shell.

      My point is that I see the fact that we needed a strong string processing language to help with shell pipelining as a flaw in the way pipelines are handled. I also see the fact that so much good functionality is exposed as Perl or Python modules, but not as shell utilities, as indicative of a severe limitation in what the shell is capable of as a programming language (overcoming this limitation goes beyond just adding a stronger set of data types to the shell language itself - the shell would also need to be able to use these datatypes as part of its pipelines.)

      Something like Perl Shell overcomes one part of the problem - turning Perl into a shell, exposing all the Perl libraries in the process... The problem is that, while such a shell provides a richer programming environment, it doesn't do anything to extend that functionality to libraries or programs not written as Perl modules. You could think of it as a problem of adoption: if Perl Shell were the standard shell on Linux then people would write their programs to work nicely in it, and the result would be a strong shell environment. But since it's not, people don't, and so the solution only goes half-way.

      --
      Bow-ties are cool.
    3. Re:The Unix Shell and Scripting Languages by bar-agent · · Score: 1

      My point is that I see the fact that we needed a strong string processing language to help with shell pipelining as a flaw in the way pipelines are handled. I also see the fact that so much good functionality is exposed as Perl or Python modules, but not as shell utilities, as indicative of a severe limitation in what the shell is capable of as a programming language (overcoming this limitation goes beyond just adding a stronger set of data types to the shell language itself - the shell would also need to be able to use these datatypes as part of its pipelines.)

      If you haven't taken a look at Microsoft's PowerShell, do so. It seems to effectively solve this problem. Of course, it is significantly less effective in the Unix and Mac environments...but the concept is cool in its own right.

      --
      i'd hit it so hard, if you pulled me out you'd be the king of britain [bash.org]
    4. Re:The Unix Shell and Scripting Languages by SL+Baur · · Score: 1

      I feel like this situation is a problem - I believe in what some people call "The Unix Way" - chaining together small tools to do bigger jobs, but the shell doesn't have the organizational constructs to make this work for complex problems - and as a result people are doing this great work on adding functionality to the system, but it's getting packaged up as scripting language modules since the shell can't handle it. It's something I'd really like to correct.

      Small programs, doing one thing well is an idea that has lost in the marketplace of ideas. We can deal with it.

      Philosophically, I am opposed to the methodology XEmacs (and other monolithic systems) represents, realistically, I can live with it - I have to. Practically, I've seen attempts at following the small piece model done so badly in the workplace that I'm not convinced anyone can make it work. For an Open Source example, see /bin/true in Stallman's GNU. Any real programmer would be ashamed of that.

  23. Single-language platforms by tepples · · Score: 1

    I always wondered, why one would implement yet another language, when one can simply use dynamic libraries or include the JIT compiler functionality of one's preferred language in it.

    Back then, it's because UNIX was young, and it didn't yet have a standard interpreted language, as Sir Groane pointed out.

    Nowadays, it's because you have to deploy your app on a half-dozen platforms, each with a different preferred language. For instance, XNA has C#, J2ME MIDP has Java, iPhone has Objective-C, Internet Channel has ActionScript, etc. The easiest way is to write your business logic in one language, and then write either interpreters in the deployment languages or compilers from your language to the deployment languages.

    1. Re:Single-language platforms by Hurricane78 · · Score: 1

      No. Not to the deployment languages. To the deployment platforms.

      So you compile to the processorâ(TM)s native machine language, instead of adding yet another intermediate layer of "fail".

      And if this machine happens to be a virtual machine, you can still do that. You can always compile to Java byte code. Or anything else really.

      Oh, and I do not write business logic. I write game rules and world physics. Much more fun. :D

      --
      Any sufficiently advanced intelligence is indistinguishable from stupidity.
    2. Re:Single-language platforms by tepples · · Score: 1

      You can always compile to Java byte code.

      I'm in the early phases of translating a design document into a multi-platform video game, and I want the different versions to use identical simulation logic even if their frontends are completely different. What one language can be compiled into verifiably type-safe JVM bytecode for MIDP mobile phones, verifiably type-safe CLR bytecode for Xbox 360 and Silverlight, Flash 7 ActionScript bytecode for Wii, x86 machine language for Windows and GNU/Linux, and ARM9 machine language for iPhone, GP2X, Pandora, and Nintendo DS? Or what platforms are worth culling?

      Oh, and I do not write business logic. I write game rules and world physics. Much more fun. :D

      In grandparent, I intended "business logic" to include game simulation logic. I tried to shy away from mentioning games because a lot of Slashdot posters have decried multi-platform video game development as not taking advantage of any platform at all.

  24. Yes, PowerShell by benjymouse · · Score: 4, Informative

    Available from Microsoft for XP, 2003; included in Server 2008 and Windows 7.

    The name is really lame, but it *is* damn powerful. At least for Windows which has most of it API exposed through object-oriented technologies (COM, .NET and WMI) which are easily used in a unified way by PowerShell.

    Just a few quick samples:

    • List all .exe files in current dir and below: ls -r . *.exe
    • Calculate their combined size: ls -r . *.exe | measure -sum Length
    • Find the latest version of all .exe files below the current directory: ls -r . *.exe | sort -des LastWriteTime | group Name | %{$_.Group[0]}
    • Instead of finding the latest, delete those with a more recent version somewhere: ls -r . *.exe | sort -des LastWriteTime | group Name | %{$_.Group|select -skip 1} | rm
    • Read files and directories from current directory out loud through the speakers: $sam=new-object -com SAPI.SPVoice; ls | %{$sam.Speak($_)}
    • List processes consuming (the "working set") more than 100MB: ps|?{$_.WS -gt 100MB}
    • -Kill them instead: ps|?{$_.WS -gt 100MB}|kill
    • Wait for the "import" process to exit: (ps "powershell_ise").WaitForExit()
    --
    Reading slashdot one-liner: (irm http://rss.slashdot.org/Slashdot/slashdot).rdf.item | fl title,desc*
    1. Re:Yes, PowerShell by wumpus188 · · Score: 1

      Here's another example: finding all empty folders below the current one

      In PowerShell:


      $a = Get-ChildItem . â"recurse | Where-Object {$_.PSIsContainer -eq $True}
      $a | Where-Object {$_.GetFiles().Count -eq 0} | Select-Object FullName

      Using find:

      find . -type d -depth -empty

      Hmm... No COM, .NET or WMI technologies required.

    2. Re:Yes, PowerShell by buchner.johannes · · Score: 3, Insightful

      We should make a coreutils package that outputs XML, JSON or similar, so we don't need stupid cut/grep/head tricks anymore and can, for example, directly access a column, or sum stuff up.

      The last command in the pipe chain would output in a user-readable format.

      --
      NB: The message above might reflect my opinion right now, but not necessarily tomorrow or next year.
    3. Re:Yes, PowerShell by Mr+Z · · Score: 1

      As a long time UNIX / Linux user, I must say I'm impressed.

      I do find it amusing that commands I'd expect to be named "dir" and "del" are spelled "ls" and "rm", though. :-)

      It definitely seems to draw heavily from the UNIX and Perl tradition, right down to $_. I will say that %{...} seems to one-up perl in the "not obvious what it does" department. Is that the PowerShell equivalent of $(...) from bash?

    4. Re:Yes, PowerShell by dargaud · · Score: 1

      | %{$sam.Speak($_)}

      Perl ? is that you ?!? Stop playing with the MS kid, he'll give you measles.

      --
      Non-Linux Penguins ?
    5. Re:Yes, PowerShell by dargaud · · Score: 1
      Some of your examples are impressive and would be hard to replicate simply in bash, but that's too little way too late.

      For almost 2 decades I taught myself the most of batch scripting, constantly hitting the wall of its limitations. Then I tried various shitty POSIX tools for Windows. Then when Cygwin came out it was a revolution, I always had 5 cygwin shells open at the same time. But now it's too late for me, if I spend more time in a cygwin bash shell than in Windows Explorer, I might as well jump ship and go off to Linux, which I did professionally and personally within the last 2 years.

      On the other hand Unix shell scripting has always been about piping text from one command to the other (and the return value), while your examples clearly show more going on with some data structure being transfered and finally converted to text. It's certainly powerful, but having had to deal with it on some other scripting language like ROOT, I find that you never know what is going on or what it's possible to do with the returned and mostly hidden structure.

      --
      Non-Linux Penguins ?
  25. PowerShell ideas are more relevant to Windows by benjymouse · · Score: 1

    PowerShell ideas are more relevant to Windows than they are to *nix. PowerShell is object-oriented: The pipes are objects, not text. That saves a lot of parsing and allows interaction (like calling methods) with the objects flowing through.

    PowerShell also unifies the object-oriented models on Windows: COM, .NET and WMI. Most of Windows APIs are now either fully object-oriented (e.g. DirextX, Speech) or have been wrapped in by object-oriented models such as .NET or WMI.

    *nix generally does not expose API in object-oriented fashions. Hence, most of the advantages that PS may have from being OO are not really relevant on *nix.

    That said, some of the other less prominent features of PS could conceivably be relevant for *nix shells, such as unified scripting, better type system and integrated regular expressions.

    --
    Reading slashdot one-liner: (irm http://rss.slashdot.org/Slashdot/slashdot).rdf.item | fl title,desc*
    1. Re:PowerShell ideas are more relevant to Windows by SL+Baur · · Score: 0, Flamebait

      PowerShell ideas are more relevant to Windows than they are to *nix. PowerShell is object-oriented: The pipes are objects, not text. That saves a lot of parsing and allows interaction (like calling methods) with the objects flowing through.

      What's the frequency, Kenneth? I'd like to debate you, but I'm not sure it's worth it when you are that clueless. Pipelines are directed graphs in modern Unix shells. (And bringing up OO is just dickwaving).

      See some of my posts on this thread which may be above this one. Like http://tech.slashdot.org/comments.pl?sid=1150373&cid=27089093

  26. PowerShell and critique of the Unix shell by Tetsujin · · Score: 4, Insightful

    so users can express themselves using the same basic style as they'd use in a Unix shell, but working with a more powerful set of libraries and data types.

    Like a Unix user would be calling Perl or Python?

    Not quite... The shell user can call Perl or Python to access libraries or datatypes - but these concepts are meaningless within the framework of the shell itself. In Powershell, a commandlet returning an object yields something you can work with in the shell - see what object methods or data fields it provides, run methods, pass the object to another commandlet, etc.

    Powershell provides a powerful set of baseline assumptions for the format of data over the pipe - and so both the shell itself and commandlets running in the shell can take advantage of these assumptions. In Unix, the typical approach is to "roll your own format" each time - which is trivial for trivial problems, but substantially harder as you start worrying about questions like, what happens when my data fields contain the character I want to use as a delimiter?

    This is further complicated by the fact that existing Unix programs, outputting text, typically format that text for human consumption. The exact format of a program's input or output may change from release to release with no coherent strategy for establishing any kind of compatibility. In comparison, in Powershell a piece of data passed from one process to another has a predictable underlying structure - it's formatted for consumption by another process rather than for display at the terminal. But since the shell itself also recognizes this format, it has a reasonable default behavior for displaying a command output - or if necessary you can pipe through a command whose job is to make nicely formatted output of selected columns of another program's result.

    Now, what are the benefits of serializing to text format? You can look at it, printed on-screen, and know what it represents and how to parse it, right? The problem is this becomes less and less true as the data format becomes more intricate, more comprehensive - which is bound to happen as you start doing things like handling more complex problems, implementing data formats that account for future upgrades, and so on. The strength of PowerShell's approach (the same approach, basically, as you'd find in any other capable, interactive programming language) is that it knows enough about the format of data it handles that it can make that format easy to view and work with - easier, in fact, than plain text, because you see a representation of the data's meaning rather than of its underlying structure.

    As another example, consider what it would take to provide any kind of higher-order programming in the shell. There's a limited degree of this available already, of course: if you want to pass a "function" to something, you form it into a shell script, put it in a directory somewhere, and provide the full pathname to that function as an argument to your higher-order program - which will then use something like "system()", "popen()" or "exec()" to invoke it.

    Now, what if you want to include a set of data, representing the state of an "object" with that "function"? You can do that, too - you can write out a data file representing the current state, and pass both the script and the data file names to your higher-order program. Or you could have a program running in the background, communicating via some form of IPC - maybe over a named pipe or listening to a particular network socket or hosted by an object broker, and pass the necessary reference to the higher-order function. Or, about the nicest you can manage in the shell (though decidedly not a clean solution IMO) - start a process in the background which maintains the state you're working with, and have a second executable which communicates with the background process, passing on commands and bringing back results.

    The problem is, none of those me

    --
    Bow-ties are cool.
    1. Re:PowerShell and critique of the Unix shell by anothy · · Score: 1

      PowerShell improves on the functionality offered by Unix shells in that it gives you a richer set of expressive fundamentals; the shell is smarter, knows more about the environment, and that lets it do more with what's around.

      the problem is that this isn't simply an extension of the Unix shell; it's actually antithetical to it. the issue isn't the "shell" per se, but the "tools" model of environment and application building. the unix shells are all intentionally fairly ignorant of the environment: they rely on some basic conventions about how programs behave, but beyond that they just move bytes (typically text) around. you can't "improve" the unix shell environment by making it have a more PowerShell-like vocabulary, because it's a vocabulary for things it simply has no knowledge of in the first place.

      this is actually a really good thing within the unix- or tools-based environment. in this model, it's a lot easier to generate new bits of functionality without having to muck around with the existing stuff. adding new functionality to the environment doesn't involve changing your shell, just adding a new tool. each tool is easy to digest and understand, and that ability to fully understand the building blocks is what leads to things getting put together in new, interesting, and unexpected ways.

      if, as you say, you're interested in looking into how that environment could best be improved upon, i'd advise you to check out Plan 9 or Inferno. they take the "everything is a file" idea from unix and extend it much, much farther. the result is the same sort of "feel" of unix, as far as user interaction goes, but a much, much richer set of expressive abilities. think about Linux's (Plan9-inspired) proc file system, extended to almost every resource in the system (and presented in a more consistent way).

      there are interesting ideas in PowerShell; this is in no way intended to be Microsoft bashing. i do, philosophically and practically, believe the tools-based approach to be superior in terms of flexibility, extensibility, and learnability, but that's shouldn't be read as an assertion that other ideas shouldn't be tried. all i'm saying is that shoehorning PowerShell concepts into a Unix shell isn't likely to give you the results you want.

      honestly, it's more similar to something like AppleScript. which is great: i like AppleScript's power, but have often found it to be pretty awkward to use and wished it "felt" more like a "regular" shell. maybe PowerShell can do that, which would be great.

      --

      i speak for myself and those who like what i say.
    2. Re:PowerShell and critique of the Unix shell by colinrichardday · · Score: 1

      Powershell provides a powerful set of baseline assumptions for the format of data over the pipe - and so both the shell itself and commandlets running in the shell can take advantage of these assumptions.

      But what if the assumptions are wrong?

      And does Powershell have assumptions about every file type? Does it grok TeX/LaTeX dvi files?

      Also, Unix users don't want the shell to be one huge all-encompassing language.

    3. Re:PowerShell and critique of the Unix shell by Spit · · Score: 1

      There is no requirement for stream output to be ascii, that is up to the programmer to decide and preferable to having the architecture decision forced on you. But I think you're missing the point that you can actually use Perl or Python as your shell, you have a semantic roadblock from working too closely with monolithic solutions.

      --
      POKE 36879,8
    4. Re:PowerShell and critique of the Unix shell by Tetsujin · · Score: 1

      There is no requirement for stream output to be ascii, that is up to the programmer to decide and preferable to having the architecture decision forced on you.

      There's a big difference between having an architecture forced on you and having an architecture provided for you. Structure is beneficial. So why is the exact amount of structure provided by the Unix shell the right amount? Is it just tradition? Or fear of attempting to set a policy people might not like?

      I think having a shell policy like "you can put whatever data format you like in your pipelines, but you have to at least agree to some standard rules about identifying what form you're using" would be a huge improvement in terms of what the shell could do with that data.

      But I think you're missing the point that you can actually use Perl or Python as your shell, you have a semantic roadblock from working too closely with monolithic solutions.

      Which monolithic solutions would those be, exactly? Please, do tell me all about myself. :D

      Neither Perl or Python is, as a language, well suited to use as a command shell. They are languages with their own environment, in which system files and commands on the PATH are external entities, while in a command shell your environment is the filesystem.

      Of course, one of these languages could be the starting point for such a shell, and the end result could provide capabilities similar to what Powershell has. The reason I don't favor something like that, however, is that I would want the shell-provided data interchange format (or formats) to be independent of any one scripting language. If the whole shell were just a Python program, and the data passed between "commandlets" just Python objects, that wouldn't get you anywhere in terms of improving the interaction between the shell and outside processes.

      --
      Bow-ties are cool.
    5. Re:PowerShell and critique of the Unix shell by Tetsujin · · Score: 1

      Powershell provides a powerful set of baseline assumptions for the format of data over the pipe - and so both the shell itself and commandlets running in the shell can take advantage of these assumptions.

      But what if the assumptions are wrong?

      You could as easily ask "what if Python's assumptions about the format of classes doesn't match the assumptions made in this compiled Python module?" It represents a failure to build the module properly for the environment in which it'll run.

      In Powershell's case, a pipeline between two commandlets (Powershell-native programs) is a series of .NET objects. A pipeline in which both of the commands are non-commandlet programs would deal in text, like a Unix shell. A pipeline in which just one of the two is a commandlet - I'm not sure.

      And does Powershell have assumptions about every file type? Does it grok TeX/LaTeX dvi files?

      Powershell doesn't do any kind of object layer on top of regular files. Data files are treated pretty much analogously to how they'd be treated in Unix.

      Also, Unix users don't want the shell to be one huge all-encompassing language.

      Speak for yourself.

      First off, the shell is "one huge all-encompassing language." It is a programming language, designed for interactive sessions, whose primary environment is the filesystem as a whole. In that role, I just want to make it more capable.

      I am a Unix user, and I want my shell to be cleaner and more powerful than what "bash", etc. can provide. I want it to foster an environment in which programs can communicate better with one another. I want programs to be written in such a way that they can facilitate these changes. It's a lofty goal, for sure, but I think the kind of shell environment we'd achieve would be worth it.

      --
      Bow-ties are cool.
    6. Re:PowerShell and critique of the Unix shell by Spit · · Score: 1

      Python and Perl exist because some things are out of scope for a shell. What do you gain by giving a shell kitchen-sink functionality? Over complicated shell. Unix shell is successful because it is simple to understand and build command chains by checking the output before the next step.

      If you wanna get fancy, time to dump sh.

      --
      POKE 36879,8
    7. Re:PowerShell and critique of the Unix shell by Tetsujin · · Score: 1

      PowerShell improves on the functionality offered by Unix shells in that it gives you a richer set of expressive fundamentals; the shell is smarter, knows more about the environment, and that lets it do more with what's around.

      the problem is that this isn't simply an extension of the Unix shell; it's actually antithetical to it. the issue isn't the "shell" per se, but the "tools" model of environment and application building.

      I'm confused here. By the "tools model of environment and application building" - do you mean the Unix tradition of "many small, simple, single-job utilities"?

      To me, that model can only be made better by giving these tools a more powerful standard of communication - reducing the amount of translation steps that need to be introduced (manually, that is, by the user) into a pipeline. Deciding on standards for calling arguments, pipeline data format, etc. would make it easier to link "small, simple" tools together - the tools themselves would be simpler by virtue of greater consistency and the eliminated need for features that might have been added to simplify communicating with partners of unspecified data format.

      the unix shells are all intentionally fairly ignorant of the environment: they rely on some basic conventions about how programs behave, but beyond that they just move bytes (typically text) around.

      The thing about that kind of design decision is that it's easy - you don't have to think too hard about the design direction, or do much work to get people to use it - but it's not necessarily the best decision in terms of what you can do with it. It's not a design that scales well: as a text format becomes more complex the problem of handling it (parsing, serializing, etc.) becomes more complex as well - and the advantages of it being a text format start to disappear.

      you can't "improve" the unix shell environment by making it have a more PowerShell-like vocabulary, because it's a vocabulary for things it simply has no knowledge of in the first place.

      This is getting a bit abstract for me... You're saying the shell can't take advantage of vocabulary without knowledge of how to use it. I disagree.

      For starters, there are some very generic ways a shell could take advantage of a little bit of knowledge about the structure of the data it's dealing with. Providing automatic translation to a related data type, for instance.

      this is actually a really good thing within the unix- or tools-based environment. in this model, it's a lot easier to generate new bits of functionality without having to muck around with the existing stuff. adding new functionality to the environment doesn't involve changing your shell, just adding a new tool.

      Why would a new bit of functionality require a new shell? What's the case where that would happen?

      And what would it take, for instance, to add a field to "crontab" or "/etc/passwd"? Those formats are dead-simple and look nice printed byte-for-byte on a terminal or line printer but the tradeoff is that they're non-extensible formats. It's a lot easier for a data format to be extensible if you don't worry so much about making it look nice in ASCII view - and then you can make the format easy to work with in practice by providing tools (including the shell) that know how to view and edit it.

      each tool is easy to digest and understand, and that ability to fully understand the building blocks is what leads to things getting put together in new, interesting, and unexpected ways.

      A shell that can understand and process the data output of the commands it runs makes the tools easier to understand. A shell that establishes standard policies for a program to publish its valid command line switches makes the program easier to use. And a shell that reduces the amount of work the user has to do to translate the outpu

      --
      Bow-ties are cool.
    8. Re:PowerShell and critique of the Unix shell by Tetsujin · · Score: 1

      Python and Perl exist because some things are out of scope for a shell. What do you gain by giving a shell kitchen-sink functionality? Over complicated shell. Unix shell is successful because it is simple to understand and build command chains by checking the output before the next step.

      Why should anything be out of scope for the shell? Why should the shell language not be capable of the same things we expect from Perl or Python? I think we have accepted these limitations because we are accustomed to them.

      Being able to check the output while building a pipeline doesn't get you much: you still need to be able to write a parser to handle that input (which is easy for simple problems, but can get challenging) - and anywhere along the line there may appear in the data something you didn't account for, with the result that when you run your pipeline it does something you didn't want, or doesn't do something you did want. Besides which, that capability is nothing special - it exists in practically every interactive programming language ever made.

      Imagine if the shell mandated just one bit of structure on the format of data going over the pipeline: how to know when one value ends and the next one begins. Just that one feature would simplify shell programming a lot.

      It's not about "kitchen sink"ing the shell - the functionality in question is already a part of your system in the form of libraries and scripting language modules. It's just a matter of giving the shell a good way to use it.

      --
      Bow-ties are cool.
    9. Re:PowerShell and critique of the Unix shell by Spit · · Score: 1

      I see where you're coming from and the GNU extensions bring some extra ability in that area, but I'm all for using the right tool for the job. Perl is the swiss-army chainsaw, also hammers nails. :)

      --
      POKE 36879,8
    10. Re:PowerShell and critique of the Unix shell by anothy · · Score: 1

      By the "tools model of environment and application building" - do you mean the Unix tradition of "many small, simple, single-job utilities"?

      yes.

      To me, that model can only be made better by giving these tools a more powerful standard of communication...

      there's some truth to that. but it's not clear how you can do that without increasing the complexity of the individual tools, and making them more aware of their environment. the tools model works as well as it does precisely because the individual tools are, well, dumb.

      The thing about that kind of design decision is that it's easy - you don't have to think too hard about the design direction, or do much work to get people to use it - but it's not necessarily the best decision in terms of what you can do with it.

      again, you're right in a significant way, but something else is missed. the point is that it's "easier" for every tool. it works best in an environment where you're going to have not a dozen but a hundred tools, written by different people. as the number of tools increases, the incremental cost of increased complexity requirements goes up by that multiple.

      It's not a design that scales well...

      i think that's exactly wrong, actually. it scales very well, because the incremental costs are so low. although, really, it depends what dimension you're trying to scale across, and i suspect we mean different things here.

      ...as a text format becomes more complex the problem of handling it (parsing, serializing, etc.) becomes more complex as well - and the advantages of it being a text format start to disappear.

      i'm not entirely sure what you mean here, but it sounds like an entirely valid criticism against tools that do a bad job of implementing the model. look at ping, or ps. on modern Unix systems, their output isn't just the data, but some "pretty" header and footer lines. if you want to use this as input to another program, you're right - you need to pre-process the output, and that adds complexity. but that's because those tools are breaking the model: as Doug McIlroy said:

      Expect the output of every program to become the input to another, as yet unknown, program. Don't clutter output with extraneous information. Avoid stringently columnar or binary input formats. Don't insist on interactive input.

      compare the behavior of these tools on a modern Unix to Plan 9, where this tenet is much more consistently followed.

      i'm not sure what you mean by the shell providing automatic translation. if the tools follow the above rule, that's a no-op, mostly, and to the extent that some translation is needed, it seems like that'd be a general enough use to warrant a tool.

      i'd rather be asked to add a field to a cron taking plain text input than xml. looked at launchd? i've tried.

      A shell that can understand and process the data output of the commands it runs makes the tools easier to understand.

      i think that's less likely to be true than you think. if you try to do something "unusual", it's likely that the shell will try to impose its view of the world on you. "intelligence", in software tools, is generally a bad thing.

      A shell that establishes standard policies for a program to publish its valid command line switches makes the program easier to use.

      this would be a good capability to have, certainly but i don't really see what it has to do with a shell. you'd need every tool to support it (or at least all the tools you want to get the benefit from), for starters. and what would be the role of the shell here? in order for it to make any sort of practical use of the information, you'd need to understand lots of semantics about those options, not just what they are.

      --

      i speak for myself and those who like what i say.
    11. Re:PowerShell and critique of the Unix shell by SL+Baur · · Score: 1

      There is no requirement for stream output to be ascii, that is up to the programmer to decide and preferable to having the architecture decision forced on you.

      ++insightful

      You can always layer on top of a simple stream of data XML or whatever.

      RMS[1] is a proven market loser. The byte streams of simple Unix files won. Now they're coming back like zombies, or the Black Knight in Monty Python and the Holy Grail.

      [1] Record Management System in VMS, the same guys who brought you Microsoft Windows NT.

    12. Re:PowerShell and critique of the Unix shell by colinrichardday · · Score: 1

      You could as easily ask "what if Python's assumptions about the format of classes doesn't match the assumptions made in this compiled Python module?" It represents a failure to build the module properly for the environment in which it'll run.

      Of course, in Python I might have access to the source from which it was compiled. Hoe much of the source to Powershell is available?

      You say that you want programs to communicate better with each other, better in what way? It may be that Powershell can do what you want in Windows, but this may be because Windows supports such a shell. The problem in writing such a shell for Unix is that the OS itself may lack features to support it. Indeed, if Eric Raymond is correct, Unix was designed not to support such features.

    13. Re:PowerShell and critique of the Unix shell by Tetsujin · · Score: 1

      You could as easily ask "what if Python's assumptions about the format of classes doesn't match the assumptions made in this compiled Python module?" It represents a failure to build the module properly for the environment in which it'll run.

      Of course, in Python I might have access to the source from which it was compiled. Hoe much of the source to Powershell is available?

      That's not likely to be much of an issue in Powershell. Since the whole thing runs on .NET, the shell and the commandlets share the same idea about how data is represented anyway...

      The point is, though, that there are always ways in which an add-on module can be mismatched to the environment in which it's supposed to run. At the shell you could have a binary compiled for the wrong platform, or linked to the wrong standard library.

      And if you want to talk about compatibility of this format between releases - that really just becomes a more centralized burden when you're dealing with a more rigorously defined data exchange format.

      You say that you want programs to communicate better with each other, better in what way? It may be that Powershell can do what you want in Windows, but this may be because Windows supports such a shell. The problem in writing such a shell for Unix is that the OS itself may lack features to support it. Indeed, if Eric Raymond is correct, Unix was designed not to support such features.

      Powershell is just an example of this approach. The reasons it works well in Windows are because it has extensive access to Windows APIs and because it has the .NET environment supporting it, acting as a stable binary platform for modules supporting reflection.

      What Unix was designed for, years ago, doesn't concern me so much. It is capable of acting as the basis for platforms beyond its basic design. This is done all the time with GUI environments, for instance.

      If you dropped the whole .NET angle and some of the other syntax features and just wrote a Unix shell that was a straightforward clone of the Powershell model, it would be something like this:

      • At the simplest level, it's an ordinary shell
      • However, it also supports another PATH-like variable on which it can find binary modules which can be run like ordinary commands.
      • These binary modules would all follow an API defined by the shell governing how they take data in and write data out
      • The data objects being read and written would similarly follow a few basic rules - a common mechanism for memory management and method invocation, some mandatory methods (like the one used to display the object on-screen as text), and so on.
      • The shell has support for working with the objects output by these commands - it can store them in variables, display them (by invoking the objects' display methods), it gives the user a way to find out what other methods the object supports, and allows the user to invoke those methods.
      • Some capability is provided to make these loadable module-commands interact nicely with ordinary programs on the PATH.

      There's nothing about the basic concept that exceeds what Unix is capable of, or even (IMO) what it was "designed for". All the above design needs is "dlopen()" combined with some establishment of policies. And, of course, there are other ways you could implement the same sort of capabilities. (For instance, to run these commands as separate processes - which might be a preferable approach on Unix since it does not ordinarily provide the kinds of protections available to code running in .NET)

      --
      Bow-ties are cool.
    14. Re:PowerShell and critique of the Unix shell by colinrichardday · · Score: 1

      That's not likely to be much of an issue in Powershell. Since the whole thing runs on .NET, the shell and the commandlets share the same idea about how data is represented anyway...

      The point is, though, that there are always ways in which an add-on module can be mismatched to the environment in which it's supposed to run. At the shell you could have a binary compiled for the wrong platform, or linked to the wrong standard library.

      I assume that Microsoft could get this right for its own software, and put pressure on other software vendors to conform (although many failed to deal with user data properly in their WinXP releases).

      These binary modules would all follow an API defined by the shell governing how they take data in and write data out

      And what of programs that don't follow this?

      The data objects being read and written would similarly follow a few basic rules - a common mechanism for memory management and method invocation, some mandatory methods (like the one used to display the object on-screen as text), and so on.

      So Eric Raymond's warning about having programs know too much of each others internal workings means nothing to you? How would one get the data objects? From the shell? Or from programs written in a zillion languages? You expect some common mandatory methods, even from data objects in languages without OO?

      It seems to me that you require a great deal of coordination between your shell and executables. How would you achieve this? Would the shell be able to deal with any executable? Or would programmers in other languages be expected to conform to the shell? The former seems difficult enough, but achieving the latter would be as easy as herding molecules.

      The problem you face is political rather than technical. Microsoft might be able to exert enough pressure to achieve such a shell. For one thing, it can make .NET the official platform of Microsoft Windows. But even if the Mono project could clone .NET perfectly, it could not thereby make Mono the official platform of Linux.

    15. Re:PowerShell and critique of the Unix shell by Tetsujin · · Score: 1

      The point is, though, that there are always ways in which an add-on module can be mismatched to the environment in which it's supposed to run. At the shell you could have a binary compiled for the wrong platform, or linked to the wrong standard library.

      I assume that Microsoft could get this right for its own software, and put pressure on other software vendors to conform (although many failed to deal with user data properly in their WinXP releases).

      It's simpler than that. If you want to write a commandlet for Powershell and have it work nicely, you do that. (If not, you don't.) People who are working in the .NET environment are halfway there already, of course... In such a case interfacing to Powershell is probably a handy way to perform unit testing and so on...

      These binary modules would all follow an API defined by the shell governing how they take data in and write data out

      And what of programs that don't follow this?

      Such programs (I have a handy name for them: I call them "every program I've ever used" :D) would simply not be able, out of the box, to take advantage of the extra functionality the shell has to offer. In Powershell this means they'd work more or less like they would in more traditional shells - piping text, and able to communicate with Powershell "commandlets" only in terms of textual repesentations of objects, as opposed to references to live objects.

      The data objects being read and written would similarly follow a few basic rules - a common mechanism for memory management and method invocation, some mandatory methods (like the one used to display the object on-screen as text), and so on.

      So Eric Raymond's warning about having programs know too much of each others internal workings means nothing to you? How would one get the data objects? From the shell? Or from programs written in a zillion languages? You expect some common mandatory methods, even from data objects in languages without OO?

      OK, first, I'm talking about Powershell's approach here, describing it in Unix terms, and how the same approach would be implemented without .NET. I wanted to clarify what it does, and how. This isn't the approach I advocate for Unix, personally...

      Second, when you're talking about something esr said - I don't know what it was, or in what context. The way you're talking about it, though, it almost sounds like you're saying I should heed that warning because he's Eric Raymond. At face value I'd say it's a question of how far the approach is taken. If you go n steps in terms of mandating common conventions between programs, that's what you'd call a coherent architecture. Go n+m steps, and you get excessive dependence on implementation details, etc.

      As for "expecting common methods, even from languages that don't support OO" - sure, why not? It's not as though non-OO languages are fundamentally at odds with the idea of OO code, they just don't have nice support for it. To get a usable object interface you need a few common conventions followed. It just doesn't work otherwise.

      It seems to me that you require a great deal of coordination between your shell and executables. How would you achieve this? Would the shell be able to deal with any executable? Or would programmers in other languages be expected to conform to the shell?

      I have given all these problems a great deal of thought. I'll describe here how I plan to solve these sorts of problems. My approach is a bit different from Powershell's for various reasons...

      First: In Powershell, the "commandlets" are dynamically linked in and run as part of the shell's process. That can work in .NET beca

      --
      Bow-ties are cool.
  27. Why so verbose? by benjymouse · · Score: 2, Informative

    when

    ls -r | ?{-not($_|ls)}

    would suffice?

    Explanation:

    1) list all items recursively from the current location

    2) filter only those items where ls returns an empty set.

    Btw, the objects returned from that command are *still* DirectoryInfo objects, allowing even further operations or property accesses.

    Also, this command will work the same even if the "current location" is a node in the registry, the certificate store, the credentials store, a group in active directory etc etc.

    In other words if you change the location to an organisational unit in AD, the exact same command will find empty sub-containers.

    --
    Reading slashdot one-liner: (irm http://rss.slashdot.org/Slashdot/slashdot).rdf.item | fl title,desc*
  28. Re:"Just USE UNIX..." by Paracelcus · · Score: 1

    Sorry to state the obvious, but Linux IS a flavor of UN*X regardless of what the lawyers at the Open Group say.

    --
    I killed da wabbit -Elmer Fudd
  29. Re:This reminds me of goatse by Anonymous Coward · · Score: 0

    jesus fucking christ!!!! how the hell do you explain that to the ER??!!?!?!

  30. Mod parent up, please by benjymouse · · Score: 1

    I have no points to give you, but this is *the* most insightful post I have seen on the topic of shells on slashdot. Ever.

    I still think that PowerShell can do something for Windows that is not currently possible on *nix. Until a unified object concept materializes, that is.

    --
    Reading slashdot one-liner: (irm http://rss.slashdot.org/Slashdot/slashdot).rdf.item | fl title,desc*
    1. Re:Mod parent up, please by badkarmadayaccount · · Score: 1

      Shell - that means that variables and methods in objects are as the programmer sees them - text. The issue is that you have to structure that text, associative arrays in Lua, anyone? Or - dare I say it - Javascript?

      --
      I know tobacco is bad for you, so I smoke weed with crack.
  31. Cambridge Phoenix system by Alain+Williams · · Score: 2, Interesting

    Steve was at Cambridge University (the real one in the UK), he would have used the Phoenix System, this was an on line system with a command programming language. I cut my scripting teeth on this in the 1970s. It did variable substitution and had here documents.

  32. Advocating Change in Unix Shell design by Tetsujin · · Score: 1

    I have no points to give you, but this is *the* most insightful post I have seen on the topic of shells on slashdot. Ever.

    Thanks... So many people are concerned that the current way is the best - convincing them to change to something different will be tough. But a new system can't take hold unless people are willing to embrace it. That's why I argue the point every time the topic of shells comes up... I need to be better at advocating the kind of system I want to promote, recognize things I may have assumed in error, and know more about the kinds of techniques people use to work within the limits of the shell. It's practice. :) Plus maybe I'll convince a few people along the way.

    --
    Bow-ties are cool.
    1. Re:Advocating Change in Unix Shell design by SL+Baur · · Score: 1

      The exact format of a program's input or output may change from release to release with no coherent strategy for establishing any kind of compatibility. In comparison, in Powershell a piece of data passed from one process to another has a predictable underlying structure - it's formatted for consumption by another process rather than for display at the terminal.

      I do not find the basic assumption valid (that Unix pipelines are destined for human readable output) and I also see no difference in the two cases you described above. Data representation can change too.

      Whatever it is you're smoking, pass some to me and then explain it again. Thanks.

      (I was doing this sort of thing for TRW who ought to have the software patents on it, if anyone does, over 20 years ago).

    2. Re:Advocating Change in Unix Shell design by Tetsujin · · Score: 1

      The exact format of a program's input or output may change from release to release with no coherent strategy for establishing any kind of compatibility. In comparison, in Powershell a piece of data passed from one process to another has a predictable underlying structure - it's formatted for consumption by another process rather than for display at the terminal.

      I do not find the basic assumption valid (that Unix pipelines are destined for human readable output) and I also see no difference in the two cases you described above. Data representation can change too.

      The difference is that if the .NET object format changes, compatibility with the previous format can be maintained... In contrast, if you're dealing with a shell utility whose ad-hoc data format changes, the maintenance required to support that change is not at all centralized - it affects any shell script that works with that data, and these may not be easy to identify.

      If plain text is not used for human-readability, then what good is it, really?

      --
      Bow-ties are cool.
  33. Re:"Just USE UNIX..." by treeves · · Score: 1

    And onion is a flavor of ice cream, but that doesn't mean people are going to pay for that either.

    --
    ...the future crusty old bastards are already drinking the Kool-Aid.
  34. Command substitution a "new idea?" by dpbsmith · · Score: 2, Informative

    "Command substitution was something else I added because that gives you very general mechanism to do string processing; it allows you to get strings back from commands and use them as the text of the script as if you had typed it directly. I think this was a new idea that I, at least, had not seen in scripting languages, except perhaps LISP,' he says."

    Surely this feature was present in Calvin Mooer's TRAC, circa 1964 or thereabouts. I've forgotten the distinction between expanded macros by means of single or double slashes, but I believe one or the other of them substituted the macro expansion back in the stream for further processing. My recollection is that it was fundamental to the way TRAC was used in practice. My recollection is also that TRAC was moderately well-known in the community at the time, so the idea was "in the air."

    I believe it also existed in a host of "macro" capabilities in assembly languages... familiar to me in MIDAS, an assembly language for the PDP-1 circa 1965 or so. MIDAS survived into the PDP-6 and PDP-10, may have been developed earlier for the TX-0, and I think may have been patterned on advanced macro assemblers for the IBM 709.

    1. Re:Command substitution a "new idea?" by butlerm · · Score: 1

      He is not talking about "macro substitution", he is talking about "command substitution". Big difference.

  35. My /bin/sh rules by SpaghettiPattern · · Score: 2, Informative
    As an IT pro, I recognize the significance of /bin/sh and I am very grateful for to Steve Bourne for his creation. It's the smallest (that's a good thing), consistent and standardized command set for setting up environments to run programs.

    My scripting rules on UNIX like systems:
    • Anything that can be done in /bin/sh I DO in /bin/sh.
    • Anything slightly more complex I do in Perl.
    • Anything truly complex I write in Java.
    • For writing scripts I NEVER, EVER use slightly enhanced shells like (t)csh (know for having bugs), ksh (used to be proprietary) or bash (too many features I DON'T want for simple scripts).
    • People that resort to slightly enhanced shells for scripting qualify themselves as being ... let's say ... inexperienced.
    • It pisses me off when I have to look up special csh, ksh or bash constructs in order to understand scripts.
    • Fancy variables? Reconsider or write Perl.
    • Fancy condition checking? Reconsider or write Perl.
    • Fancy arithmetic? Reconsider or write Perl.
    • Fancy system access (e.g. ipc)? Write Perl.
    • However, my favorite INTERACTIVE shell is bash. It gets the /bin/sh syntax and offers stuff that makes you extremely quick when working interactively.
    --

    I hadn't the slightest objection to his spending his time planning massacres for the bourgeoisie... (P.G. Wodehouse)
  36. Unix was the first Microsoft Vista for home users by SL+Baur · · Score: 1

    UNIX wasn't exactly one of those home-user targeted operating systems.

    When Unix came out, there were probably something like 0 home computer systems. Not much of a market there. The equivalent to the original hardware it ran on would not become available for home use until the early 1980's[1].

    I guess... but Windows did appear to try to get AWAY from the command line.

    Unix and Unix-derivatives have been moving towards windowing environments for probably longer than you've been alive, usable for me since 1987. The command line complements GUI and for me, I *must* have /bin/zsh[2] to be productive.

    [1] Which, for home use, would make it the first known example of which Microsoft Vista is the latest incarnation. Once again, Microsoft comes in 2nd in "innovation".

    [2] Besides, of course, XEmacs.

  37. Command aliases, loops and filters by benjymouse · · Score: 1

    LOL. Actually ls is an alias for the cmdlet Get-ChildItem. That's the canonical name. Other aliases are, surprise, dir and gci (no points for figuring that one out). Unlike *nix aliases PowerShell aliases are strictly aliases, i.e. they are merely alternative names for the same cmdlet. The shortcut functionality of *nix aliases are covered by PowerShell functions or filters.

    The fact that the cmdlets canonical name is Get-ChildItem hints of another concept in PS: The same cmdlets can be used against multiple types of targets. The "current directory" has been extended to "current location". A location can be in anything for which there exists a PowerShell provider. It comes with (no suprise) a provider for filesystem in which "child items" will be files and/or directories. However, also the registry is exposes as a "file system", so you can set the current location to a node in a registry hive and use the exact same commands: ls, rm, cp. Other providers are certificate store, active directory, exchange, credentials store etc.

    The % is actually an alias for the Foreach-Object. That cmdlet takes up to 3 script blocks: begin block, process block and end block. It starts by executing the begin block once, then executes the process block for each object in the pipeline and finally executes the end block once. If only a single block is defined (as in the above examples) it is assumed to be the "process" block. As PowerShell script is an expression language it will feed the pipeline with whatever the expressions in the block returns. During execution $_ (like in perl) is a reference to the current object being handled.

    --
    Reading slashdot one-liner: (irm http://rss.slashdot.org/Slashdot/slashdot).rdf.item | fl title,desc*
  38. Where were power JCL users when they were needed? by SL+Baur · · Score: 1

    I personally enjoy the challenge of writing .BAT files that rely soley on native commands.

    I'm not sure whether to laugh at you or stand up and start clapping.

    It's definitely a pity you weren't around 30 or 40 years ago to do the same thing in JCL.

  39. Late, but not too little by benjymouse · · Score: 1

    PS is definately late to the game. It was released in 2006 and until then advanced scripting on Windows required the hideous and verbose VBScript or something like it. But as you can tell PS is definately making a strong showing. It is consistent (easy when newly designed), extensible, feature-rich and yet simple to use when you get the concept.

    As for the "some data structure" being transferred, that it not what PowerShell does. It transfers interfaces to objects through the pipeline. And those interfaces can be discovered and queried.

    The Get-Member (it has the alias gm) will list the interface members (properties, methods, ...) grouped by the distinct types of objects in the pipeline.

    So the command ls | gm will tell you exactly what types of objects are in the current location and what properties/methods you can use. Furthermore you can use the Format-List * (or simply fl *) to output the values of all properties of all objects.

    --
    Reading slashdot one-liner: (irm http://rss.slashdot.org/Slashdot/slashdot).rdf.item | fl title,desc*
    1. Re:Late, but not too little by dargaud · · Score: 1
      Interesting, thanks for the details.

      So, hmm, when is the Linux version coming out ? C:-P

      --
      Non-Linux Penguins ?
  40. Why stay stuck with cheap imitations? by SL+Baur · · Score: 1

    Many Mac users have found the Unix shell hidden under Mac OS X to be quite useful.

    The Divine Shell (zsh) is installed in /bin by default. /bin/sh is bash (slowly improving, but readline will never catch up to zle, which is kind of sad, actually).

    I'm not nearly as fond of the Mac UI as am I of something like KDE 3 (my favorite all-time GUI), but it's growing on me and there's all the true Unix(tm) goodness underneath it. Add in a few things like XEmacs and some games like World of Warcraft and ding, you have yourself a winner.

    Not to mention that stuff like Mail.app uses emacs style key bindings, you gotta love that, well, at least I do.

    It won't ever meet my minimum requirements in a mission-critical system, but for something to give to my wife to use and a toy for me to play with, it works for me. Who am I kidding, keeping one's spouse happy is as mission-critical as it gets.

  41. Re:Where were power JCL users when they were neede by nuckfuts · · Score: 1

    The guy you're referring to would be my oldest brother. I remember him carrying around homework assignments that consisted of a huge stack of punch cards. My first experience with a computer of any kind was playing tic-tac-toe on a TTY at his university. It reprinted the whole grid after every move. It seemed magical to play a game against a machine opponent. As for my brother, he's retiring this year.
     

  42. Steven Bourne was a true innovator by SL+Baur · · Score: 1

    But this is old news now, Windows has a CLI. I hear it's pretty powerful too. I don't spend enough time on Windows to bother learning it, but I'm glad they have it. If there are any useful ideas there, I'm sure they'll make it into Bash or ZSH or whatever.

    Doubtful (that there's anything new in this so-called powershell). At least no one has posted anything so far that can't be done easier in a modern Unix shell.

    I'm a little less than impressed with bash, but zsh is like manna from heaven and has been so since I first discovered it in 1990 (and it's gotten better since).

    Steven Bourne deserves a lot of credit. A WHOLE lot of credit. He was the person who innovated a user interface as a full-fledged programming language and made it work. Well.

    The BSD guys came later and attempted to make a csh with better programming features.
    http://www.faqs.org/faqs/unix-faq/shell/csh-whynot/
    I will not detail my own personal pain and suffering as an emacs maintainer due to the gross misdesign of .cshrc.

    At one time I was receptive towards learning csh, but openly laughed when a coworker who was attempting to show me the "power" of csh typed a very long command substitution line that was not only longer than the original command line, but had an error in it so it had to be retyped any way. (Later on, I still ported a copy of csh & tcsh sources to a System V box, of course with a subset of features (sans BSD-only features), just for the learning experience).

    Of any fundamental programming interface design error, csh has probably caused more losses than any other single non-Microsoft program. (The default to printing an error message when an unsuccessful glob is "attempted" is #1).

    The CLI shells that have proved successful in the long run (ksh, bash and zsh), have all been based off of Bourne's work. The Bourne Shell, even unextended from its successors is incredibly powerful. Let's see PowerShell programmers do

    A BASIC interpreter:
    http://www.mtxia.com/fancyIndex/Tools/Scripts/Bourne/basic.html
    An Adventure game, suitable as a Unix shell:
    http://www.ifarchive.org/if-archive/shells/advshell.shar.Z

    1. Re:Steven Bourne was a true innovator by benjymouse · · Score: 1

      Doubtful (that there's anything new in this so-called powershell). At least no one has posted anything so far that can't be done easier in a modern Unix shell.

      How about these:

      • Pipes are object-oriented. Commands are piping objects instead of plainly text. This means that
        • subsequent commands can refer to properties instead of parsing columns trying to get delimiters right and avoid false positives
        • tools/commands do not have to worry that columns may not be wide enough
        • you don't have to suppress headers and formatting information and
        • values are passed strongly typed, i.e. dates are just dates and you need not worry about ISO formats to sort correctly.
        • text (string) is just an object type so you can still just pipe text if you so choose.
        • instead of passive text the script/commands may interact with the objects. As an example, ProcessInfo objects (returned from the ps cmdlet) expose a WaitForExit method which allows scripts to wait for a process to terminate without resorting to ps loop polling or specialized tools.
      • First class strongly typed script language is embedded. It understands floats, objects, dates, times etc. Unlike when you drop into Perl or Python, PowerShell script still allows the use of commands with full piping embedded in scripts.
      • Provider/drive architecture which is extensible. PowerShell comes with providers for file system, registry, credentials store, certificate store, environment, variables, functions and aliases. Providers are user-extensible and providers also exist for Active Directory/LDAP, Exchange etc. The upshot: You can manipulate any store just like you manipulate directories and files, using the exact same commands. You can change "current location" into Active Directory, go to an organizational unit and start adding/removing members like it were files. With the exact same commands.
      • structured, nestable exception handling using try-catch-finally blocks.
      • transaction support (v2). Lets you rollback/commit changes to file system, registry or any other transaction aware provider as atomic transactions. Yes, NTFS is transactional.
      • script signing. By default PS will not let you run any script files unless they have been signed by a trusted authority, which can be yourself, your IT dept. or a 3rd party supplier. This can be set to only block unsigned scripts received from the internet/mail or never block (stupid).
      • debugger support (v2). Not just tracing but actual debugging with breakpoints, variable inspections/changes/continue etc.
      • Culture and internationalization support. Allows localized scripts with messages from multiple language dictionaries.

      But you wanted to see something that could not be done more easily in a modern unix shell (like bash or zsh?). Let's see:

      # list all empty directories below current:
      ls . -r | ?{!($_|ls)}

      # list all directories below current which are empty except for *.tmp files:
      ls . -r | ?{!($_|ls -ex *.tmp)}

      # a better slashdot rss reader
      $wc=new-object Net.WebClient
      $rss=[xml]$wc.DownloadString("http://rss.slashdot.org/Slashdot/slashdot")
      $rss.RDF.item | ?{$_.creator -ne "kdawson"} | fl title,description

      # or just read the slashdot headlines through the speakers
      $wc=new-object Net.WebClient
      $rss=[xml]$wc.DownloadString("http://rss.slashdot.org/Slashdot/slashdot")
      $voice=new-object -com SAPI.SPVoice
      $rss.RDF.item | %{[void]$voice.speak($_.title)}

      # list threads consuming more than 100MB (working set)
      ps | ?{$_.WS -gt 100MB}

      # which 10 processes has been using most CPU?
      ps | sort -desc CPU | select -first 10

      # but how is their average CPU utilization since start?
      #(format in a table with process name and average CPU utilization in percent with 2 decimals)
      $big = ps | sort -desc CPU | select -first 10
      $big | ft Name, @{ E={$_.CPU/((get-date)-$_.StartTime).TotalSeconds}; L="CPU avg"; F="{0:p2}"}

      --
      Reading slashdot one-liner: (irm http://rss.slashdot.org/Slashdot/slashdot).rdf.item | fl title,desc*
    2. Re:Steven Bourne was a true innovator by SL+Baur · · Score: 1

      Thanks. I gave you a full response here: http://slashdot.org/~SL+Baur/journal/225315

      None of your examples seemed worthwhile in terms of making me want to run out and implement them, though the `better Slashdot rss reader' is a gem of much value.

      I'll grant that for those trapped in the Microsoft ghetto, PowerShell appears to be a Good Thing.

  43. ksh is no superset of sh! by Anonymous Coward · · Score: 0

    I know this is fully aimed at Bourne and doesn't really cover other shells, but I would have liked to see the myth debunked that the Korn shell is a full superset of the Bourne shell. This is something which has been discussed many times on Solaris forums where some people considered it a good idea to change the shell of the root user from sh to ksh because "its a full superset". Well....

    magi:/home/peter $ sh
    magi:$PWD $ cat /etc/passwd ^ grep peter
    peter:x:100:10:Solaris administrator:/home/peter:/bin/ksh
    magi:$PWD $

    ...I dont' think so :-)

    I think its interesting that even now with Solaris 10 the Bourne shell is still the de-facto shell for cronjobs and common commands:

    man sh(1)

    NAME
              sh, jsh - standard and job control shell and command inter-
              preter

  44. Re:NO, PowerShell by Anonymous Coward · · Score: 0

    OMG, not being a MS kneeler, I was unaware of Powershell. Looks like more proprietary lock in and totally obfuscated command lines.

  45. critique of the Unix shell, etc. by Tetsujin · · Score: 1

    To me, that model can only be made better by giving these tools a more powerful standard of communication...

    there's some truth to that. but it's not clear how you can do that without increasing the complexity of the individual tools, and making them more aware of their environment.

    Explain: what would make the tools more complex?
    What would make the tools more aware of their environment, and to what ill effect?

    Take "find" for example. All it needs is a fool-proof way to tell a receiving process where one filename ends and another begins. If that were provided in a more consistent way across applications, one wouldn't need "-print0" or "xargs -0", you could just chain the one command to another without any special options. Simpler.

    On the flip side, this means there's the logistical complexity of getting people to write their tools with one of the shell's preferred data formats in mind, and the technical complexity of making that happen. The latter is by far the less complicated issue, to my mind. Programs link in a library and most of the work is done for them. Just like we don't think about how the internal code for "printf" works, we wouldn't have to think about how the serialization layer works.

    the tools model works as well as it does precisely because the individual tools are, well, dumb.

    I think the tools model could work a lot better than it does. I believe people are solving problems in Perl or Python, etc., bypassing the whole suite of "small tools" precisely because these environments provide organizational structure that's missing from the shell.

    (regarding the decision to make shell programs deal in plaintext, for the most part-) you don't have to think too hard about the design direction, or do much work to get people to use it - but it's not necessarily the best decision in terms of what you can do with it.

    again, you're right in a significant way, but something else is missed. the point is that it's "easier" for every tool. it works best in an environment where you're going to have not a dozen but a hundred tools, written by different people. as the number of tools increases, the incremental cost of increased complexity requirements goes up by that multiple.

    I don't totally agree with Matz's ideas about how programming languages should be designed exclusively with the programmer in mind - I feel there has to be a balance, between the needs of the user and what the machine can provide. As it applies to this case, I'd say the needs of the user to deal with every aspect of translation steps every time they do a pipeline command outweighs the more-or-less one-time cost of writing the tools.

    ...as a text format becomes more complex the problem of handling it (parsing, serializing, etc.) becomes more complex as well - and the advantages of it being a text format start to disappear.

    i'm not entirely sure what you mean here

    Ad-hoc text formats are very simple to deal with when you're working with simple data structures. When those data structures need to be able to accommodate the possibility of future change without breaking existing code, or when you start using them to represent more complex structures, the burden of dealing with that organization at the byte-by-byte level for every pipeline you run becomes unreasonable.

    Also, as the complexity of the text-encoded data structure becomes more complex, the simplicity and clarity that make it advantageous to encode that data as text disappear - a raw byte-dump is no longer an effective way to view it.

    i'm not sure what you mean by the shell providing automatic translation. if the tools follow the above rule (that each tool assumes its output is meant to

    --
    Bow-ties are cool.
    1. Re:critique of the Unix shell, etc. by anothy · · Score: 1

      i think at this point, we just have (potentially unresolvable) philosophical differences. you talk about linking applications against a particular library for the shell, and the shell automatically transforming data, and such without recognizing that such things are antithetical to the design, intent, and evolution of the Unix shell. you seem to think that the primary reason for representing things as text is human readability, not that it's an easy, consistent way for applications to deal with things, which isn't why unix does it (or didn't used to be). and a debugger is you're example of a tool where intelligence is good, when it isn't even really a "tool" in the Pike/Kernighan/Unix sense.

      i mean it when i say your ideas are interesting, but i think it's a mistake both in implementation and in thinking about it for yourself to frame them in terms of "growing" the Unix shell or whatnot. you really are talking about a parallel universe. but just because i think it's antithetical to Unix's design doesn't mean i'd think it's bad. the original Mac, for example, was very anti-Unix, but the coherent internal design philosophy worked very well for it. similarly, there was an "anti-Mac" design philosophy going around for a while that was similarly logically coherent that i would have loved to explore an implementation of. the opposite of a great idea is often another great idea. just don't try to cram them together; that's always a mess.

      --

      i speak for myself and those who like what i say.
  46. Shell design by Tetsujin · · Score: 1

    The context of the whole discussion has changed gradually - away from Powershell as an example of the approach I'm advocating and more toward my own ideas about how such concepts could be incorporated into the shell... There is a design I've been working on - I'm pretty much dealing with this discussion now in terms of that design and what I want to accomplish with it.

    i think at this point, we just have (potentially unresolvable) philosophical differences.

    I'm OK with that if you are. :) If you don't find the discussion interesting then I'm not offended if you don't want to continue.

    In general, when I enter into a discussion like this I have to try very hard to argue the point well, and still I think I don't always make a good case for it. There's always more for me to learn, too, about how things work in the current shells.

    you talk about linking applications against a particular library for the shell, and the shell automatically transforming data, and such without recognizing that such things are antithetical to the design, intent, and evolution of the Unix shell.

    For sure it's a huge change that I'm suggesting. I feel like it's an improvement, but I understand that many people won't share my opinion.

    Writing code specifically for the shell is a somewhat alien idea, admittedly. But I think it's a good thing, if it means the shell can be substantially more powerful and capable as an interactive language as a result.

    But it's a bit misleading to suppose that we don't already write programs specifically for use in the shell. Don't we use libraries for parsing command-line arguments, for instance? Don't we adhere to a set of arbitrary conventions about how the program is started and run? Don't people generally attempt to make their shell tools' output at least somewhat easy to handle with sed, awk, etc.? I'm proposing changing out one set of conventions for another - to say it's an uphill battle would be a ridiculous understatement. :D

    That said, in my design I do recognize that working nicely with code not written specifically for the shell is critically important. That would be "every program in the world" at present. :D I try to avoid words like "legacy" when talking about such code for this exact reason. I wouldn't say I've entirely solved the problem in my design, though...

    There's different ways this compatibility can be dealt with: there's the default, minimalistic assumption about such programs (text input, text output, text stderr), and there's the option of letting the user or sysadmin statically tag the program, or wrap it in a shell script, in order to provide a translation layer (like "split text by line, split lines by colon delimiter")

    Another possible method for determining the output format of a program would be to attempt to guess - but this is difficult since normally the shell doesn't monitor a pipelined process's output at all - it just creates the pipe and then execs the processes. To monitor a pipe, even just the first dozen bytes or so, would require a second pipe, and the shell process continuing to pass data from one pipe to the next for the remainder of the execution... (Well, it might be possible to read from the read end of the pipe and then push the data back into the buffer, or something - I don't really know. I'll have to reread my Unix Programming book...) That's something I'd generally like to avoid.

    One of the places the design really fails at present is terminal applications - things like alpine, aptitude, pretty much anything that uses curses. These programs don't really take values in and write values out at all - rather, they're applications requiring a certain sort of display interface, the terminal. But Unix traditionally provides no clear way to distinguish these from "tools", so I don't have a way to make the shell automati

    --
    Bow-ties are cool.