Want to read Slashdot from your mobile device? Point it at m.slashdot.org and keep reading!

 



Forgot your password?
typodupeerror
×
Image

Book Review: Linux Shell Scripting Cookbook 173

vellorean writes "I have been reading Linux Shell Scripting Cookbook by Sarath Lakshman, published by Packt, for a while. While most people I know learn shell scripts themselves, I was looking to refresh my concepts a little as well as have a reference lying around on the table for fast access." Read below for the rest of vellorean's review.
Linux Shell Scripting Cookbook
author Sarath Lakshman
pages 360
publisher Packt Publishing
rating 9
reviewer Kumar Appaiah
ISBN 1849513767
summary A book for beginners and intermediates, which introduces shell scripting and proceeds to provide several practical real-world recipes of useful shell scripts
First of all, let me remark by saying that shell scripting is something learned more on a need basis than as a tool to solve the main problem. People would seldom write shell scripts as standalone programs (exceptions exist). However, what makes shell scripting invaluable to know is the fact that knowing some tricks can save several minutes, or hours, of work by automating and simplifying certain tasks, generally (but not restricted to) file management and data processing. Linux Shell Scripting Cookbook does go quite far in pursuing this goal, and is appropriate for both beginners who are looking to gain dexterity in shell scripting, as well as intermediate users who wish to polish their skills. The book also can double up as a quick reference, though I would argue that the "Advanced Bash Scripting Guide" would suit that more.

At the outset, the author clarifies that the focus will be on Bash. This, people may or may not like, but the fact that bash has become ubiquitous in terms of the available shells on Unix-like systems today, starting out with bash is not a bad thing to do. Besides, learning other shell scripting languages while knowing bash isn't too hard, since the paradigm remains the same.

The book is organized into chapters based more on utility than scripting concepts themselves, although the language aspects are brought onto the reader gradually. For instance, the examples in the first chapter focus more on the basic data elements (variables, arrays, functions etc.) as well as operators (for numbers, files etc.), and all the examples demonstrate simple usage of these concepts, and he further chapters build upon these in a gradual manner.

At the same time, if he reader has some familiarity with shell scripting and needs to only refresh or learn a certain concept, he/she needs to just read the relevant chapter. It is not too difficult to grasp the examples of the later chapters, provided some basic shell knowledge is assumed.

A positive trait in the presentation of this book is that it is all based on practical everyday examples which, with minor adaptation, can be used by many for their own daily tasks. For instance, there are several examples which describe searching for and processing files, which, I'd imagine, many users would want to do on a regular basis. Thus, providing realistic examples allows the book to double its utility. The language and approach used is simple and conversational, and the presentation is very clear, with each idea being described as a problem statement followed by a "How to do it" section with the actual code, and ending with a discussion of the nitty-gritties of the code. It is easy to go for a quick scan for those in a hurry, while those who with to read in more detail will not be disappointed either.

The book also covers a wide array of applications. For instance, there are examples on automating fetching web pages and processing them, demonstrations of parsing and simplifying and even some queries around databases wrapped around in shell. It also spans to utilities and tasks connected to statistics, backups, compression, version control and many more.

The book goes into a fair amount of detail in terms of describing the shell scripting concept under consideration. The examples used go into a fair amount of detail in order to describe to the user all the aspects involved in the method or command being used. The concepts described are fairly complete, and would be sufficient for the reader to use immediately or with just a little bit of fine tuning. In terms of breadth, the book covers most of the features of shell scripting while also describing the various facilities the shell provides access to in a Unix-like environment. Thus, the book does not disappoint in this front either.

In summary, probably the only thing I'd have liked to see more of is some emphasis on how to write more efficient shell scripts. Granted, most of the shell scripts described in the book are very simple and succinct, but a some words on how loops can be made better, or how to spot situations where pipes are not needed to solve a problem etc. might have been a nice addition. Some explanation of differences with dash, tcsh, zsh etc. might also have been nice, since a lot of users have different default shells. But all this isn't going to prevent me from giving this book a high rating, since it delivers quite well on the promises it makes at the beginning.

This is definitely a good book to have near your desk, and kudos to the author for having taken the effort to put it together. I would highly recommend it to the beginner and occasional shell user for a thorough read, and to an intermediate to have on his/her desk for borrowing the cool scripting ideas and applications the author has written in this book.

You can purchase Linux Shell Scripting Cookbook from amazon.com. Slashdot welcomes readers' book reviews -- to see your own review here, read the book review guidelines, then visit the submission page.

*

This discussion has been archived. No new comments can be posted.

Book Review: Linux Shell Scripting Cookbook

Comments Filter:
  • Why does anyone still use shell scripts anymore? Every major(and most minor) distro ships with python, ruby, and perl either built in or a trivial statement away. These languages give you access to basic OS functions and much more sane syntaxes. Shell scripting is something I haven't felt the need to do in 5 years.
    • by mugnyte ( 203225 ) on Friday April 15, 2011 @02:17PM (#35831924) Journal

      wow. how many ways can i answer that?

        - there is no one true way
        - people learn a skill and want to continue using it
        - concise syntax / small footprint / fast load times
        - high confidence shell scripts will run on unknown systems
        - can be layered on years of useful scripts
        - distrust of your options for doing work

      • For me its usually;

        - too lazy to learn another language or...
        - not enough time to learn another language
      • - high confidence shell scripts will run on unknown systems

        I guess it depends what you consider a "high confidence shell script". Avoiding GNU extensions to programs you run and sticking as strictly as possible to POSIX options and behavior would probably get you most of the way there, but that's a pretty big limitation.

        The way I see it, the strengths of a shell for scripting are that it's an environment truly made for running other programs and interfacing them together, and it's an automation (scripting) environment that matches your interactive session (and thu

    • by beatle42 ( 643102 ) on Friday April 15, 2011 @02:21PM (#35831972)
      I find it useful to do shell scripting when I've been doing something by hand, and want to automate it. It's pretty easy to just echo the command I've been doing into a file and touch it up from there. Then I can take advantage of the organic growth of the command as it usually happens, and can also use it to run that same command on lots of systems if needed.
      • Rah! A really good comment, saves time, works with all shells.

    • by Anonymous Coward on Friday April 15, 2011 @02:22PM (#35831984)

      Sysadmins who can't work in plain shell scripts are dangerous. What will you do if you lose your /usr filesystem ? Be stuck with no automation tools at all as you fix by hand ? Shell scripts have little or not dependencies, and can function where other languages aren't available.
      More-over they are ubiquitious. Perl, python and ruby are common in Linux, but what will you do if you're on a different Unix altogether ? A sysadmin who can use shells efficiently can easily transfer his skills to solaris, hp-ux or several others (I did just that, and now I'm paid quite a lot more than a Linux sysadmin earns as a Unix sysadmin because the skillset is rarer). Of course there are other skills you'll need to learn (package management for example is vastly different between various unixes and most are frankly primitive if you are used to Linux) but the core Unix fundamentals remain the same, and if you don't know powerful and flexible shell scripting, in my book, you're no sysadmin at all.

    • You phrase the question differently than I would. I would ask why is perl not the default shell language.

      I have a hard time understand the need for bash when perl is around. I can't quite make the same argument for Python and Ruby. THose are arguably better programming languages but not better administrative script languages. Perl on the otherhand is still very close to the common shell languages while being much more powerful. It's also faster than shell for almost every purpose where time matters.

      • by Hatta ( 162192 )

        You phrase the question differently than I would. I would ask why is perl not the default shell language.

        Because Perl is huge and sh is tiny. Would you be able to port Perl to BusyBox without dramatically increasing the size of the executable?

      • In my shop it is either bash or python take your pick, perl is not to be used on company systems.

        • by h4rr4r ( 612664 )

          I take option 3, not working there.

          Python could be nice, if it ignored whitespace/indentation. Also if it had its own version of CPAN.

        • by Bigbutt ( 65939 )

          I'm curious as to the reasons behind this. Is there some inherent problem with perl that it's banned or is it just a requirement to maintain consistency?

          [John]

      • by erice ( 13380 )

        You phrase the question differently than I would. I would ask why is perl not the default shell language.

        I have a hard time understand the need for bash when perl is around.

        [snip] Larry's mantra: simple things should be simple, and hard things possible.

        Perl isn't simple enough for basic scripting. Most shell scripts are little more that lists of commands with minimal control flow. For that, Perl is too verbose. The extra syntax means more places for bugs and it gets extra messy if you are generating scripts programatically. Now, I agree that more complex scripting should be done is something like Perl. "Advanced Bash" makes about as much sense to me as "Advanced duck tape application"

        It's too bad that Unix shell scripting languages are so dreadful.

      • by turgid ( 580780 )

        I have a hard time understand the need for bash when perl is around.

        Conversely, I have a hard time understanding why anyone would use perl when bash, Ruby and Python are around.

        A shell should be (needs to be) light-weight. Perl is not. Perl's syntax is horrendously complicated. Bash (and sh) syntax is not.

      • You phrase the question differently than I would. I would ask why is perl not the default shell language.

        For one reason, you wouldn't want to have to type in something like

        system("ls -l");

        instead of

        ls -l

        for everything you do.

        However, the exact same syntax features that make sh good for interactive prompts make it a horrible programming language. IMO, it's tied with COBOL for the worst language still in general use. I'm familiar with a couple of dozen languages, and sh is the one I find hardest to use without constantly referring back to the documentation. I can never remember its crazy variable expansion

        • by spiralx ( 97066 )

          Use IPython [scipy.org], and not only do you get an interactive Python console with tab completion, code highlighting, simple introspection, logging, macros, profiling and more, but it also acts as a shell where you can do things like ls -l, and treat the output as a Python type that you can pipe to variables and functions if you so desire. Awesome software.

      • by ncc74656 ( 45571 ) *

        You phrase the question differently than I would. I would ask why is perl not the default shell language.

        Perhaps because perl's about an order of magnitude larger:

        # quickpkg bash perl
        # du /usr/portage/packages/app-shells/bash-4.1_p9.tbz2 /usr/portage/packages/dev-lang/perl-5.12.2-r6.tbz2
        1120 /usr/portage/packages/app-shells/bash-4.1_p9.tbz2
        12372 /usr/portage/packages/dev-lang/perl-5.12.2-r6.tbz2

        • Try running bash without grep and awk some time. bash is smaller because it calls other programs. that makes it fragile if those other programs change.

          • by mvdwege ( 243851 )

            Try doing anything useful in Perl without loading modules.

            And I'm saying this as a Perl fan. I use it for everything that can't be done in a 10-line shell script, but for some simple automation tasks it is just overkill.

            Mart

    • by jandrese ( 485 )
      Because there are lots of things that are more awkward with Ruby/Python/Perl than they are with shell scripts?

      If you're running a bunch of commands on a system and just verifying return codes, a shell script is the right tool for the job. It's also the right tool for those times when you're working on a very stripped down machine that may or may not have your favorite interpreter installed.
    • by Hatta ( 162192 )

      Because I've always got two or three shells open anyway. If I'm using Bash all day anyway, why not write my scripts in it?

      There are definitely better scripting languages, but I get a lot more Bash practice than I do Perl or Python practice. That's all there is to it.

    • Since I use the shell as my preferred work environment, rolling up commands into scripts simply multiplies my existing effectiveness with very little extra effort.

      Correspondingly, what I learn from scripting improves my ability to act quickly in a 'live' shell.

      Since I work in PHP (mostly), I use it for anything that BASH can't do, since then I have access to my application libraries. If my app was in Ruby I'd use that.

    • by smcdow ( 114828 )

      initscripts. If you're not writing them, you aren't a software developer.

    • Yes, I write web applications with little to no programing. Yes I use scripts, and even some unix commands called from my HTML+scripts.

      <<date +%d/%m/%Y>>

      works on my pages. ya it prints the date... Powered by PERL.
      PS. I can read an write SQL on my web pages. no programing needed.
    • #!/bin/sh
      echo "Lot of the time it's just quick and easy"
      • by Ruke ( 857276 )
        #!/usr/local/bin/perl
        print 'I see your point. Perl is just too unwieldy in this case.';
        • by Bigbutt ( 65939 )

          /usr/local/bin/perl: bad interpreter: No such file or directory

          Shoot, perl is in /usr/bin and not in /usr/local/bin. So I'll have to ln -s /usr/bin/perl /usr/local/bin/perl and hope it works.

          [John]

    • by cptdondo ( 59460 )

      Try working in an embedded environment. When you have 4 MB of flash and 8 MB of RAM, and python (even a barely usable stripped python) takes 3 MB, you use shell. Most of my programming is on embedded platforms; if I have 32 MB of flash I don't know what to do with it. I use a lot of shell and awk.

      Don't even get me started on PERL; it works for some and for others it is the most obtuse incomoprehensible glop you can imagine. Instant cruft. And it takes megabytes of storage.

      Just because you can't see it

    • by PetiePooo ( 606423 ) on Friday April 15, 2011 @02:58PM (#35832444)
      One of my fondest hacks was a shell script. It was for an embedded Solaris box where we didn't have the ability (through written policy) to add any other programs or packages, but scripting was OK. Ultimately, it was a job for expect, as I was communicating via telnet to another platform to upload firmware. But I only had sh, csh, or ksh. I chose vanilla Bourne shell, and wrote a script that accepted as inputs the IP address to upload the file, and the name of the file to upload. It set some variables relaunched itself in the format

      exec $0 | telnet $DEST_IP | $0

      The script receiving stdout from telnet would watch for input lines, keeping track of what response was expected, and send either a USR1 or a USR2 back to the script outputting commands into telnet's stdin, which would then either bail or send the next command. It was rudimentary pass/fail error checking, but much better and faster than echo a; sleep 1; echo b; sleep 1; echo c...

      I often prefer #!/bin/sh as I know it's a common denominator on all *nix systems, and often my scripts work even if the shell is busybox. Yes, perl or python may handle the task more efficiently and with less code, but keeping fresh on Bourne shell makes it easier to fiddle with initramfs images and embedded systems with limited space and no advanced shells. In fact, I'll often stick with it just for the challenge. I like making the original Bourne shell truly sing...

      Open your eyes. There's much more to the world than just "every major (and most minor) distros." Even more than just Linux and the BSDs.

      Crikey. If nobody learned assembly, we wouldn't even have operating systems.

    • by Zenin ( 266666 ) on Friday April 15, 2011 @03:04PM (#35832496) Homepage

      In particular Bourne shell makes gluing other programs together far easier, cleaner, and more reliably then can be done with any of the languages you list...and I say that even given that I'm extremely fluent in at least two of them.

      Correctly and reliably handling even a simple "foo | bar | baz" construct in the languages you list can be done, but you're talking about an LOT of non-trivial systems level programming to do it, effectively "coding C inside perl/python/ruby". No, really. Sure, it's very easy to do it wrong and fragile (just call system(), what's so hard right?), but if you actually want to handle it as correctly and reliably as Bourne does out of the box...it's going to take a hell of a lot more code and detailed systems programming knowledge then even most "Sr" Unix sysadmins tend to have. Almost without fail ever attempted I've ever seen in the industry gets it wrong...typically very, very wrong.

      Bourne is built to run other programs, to manage the interactions between them, programming logic being the exceptional use. All of the languages you list are built to be self-contained, programming logic being the primary task and communicating with external programs a very secondary use.

      Now of course...if your script/program is self-contained and not just wrapping a bunch of exec()s of other programs, then sure Bourne shell is one of the least favorable options.

      There's also nothing saying you can't freely mix and match. Most anyone worth their salt does so all the time. To do otherwise would be like saying a web coder could only work in HTML or only work in JavaScript or only work in PHP. We're talking about complimentary languages here, with some overlap.

      Use the right tool for the job.

    • by blair1q ( 305137 )

      Shell scripting lets you turn things you do on a shell command-line into scripts, without changing them.

      That you can then cruft them up with reams of flow-of-control syntax, variables out the wazoo, optargs for days, and trap statements, is just a bonus.

      Sure you would have done it better in Python. But if you don't know Python you take what you type into the shell more than once, and make a script out of it.

    • by hawguy ( 1600213 )

      I still use Bash for most automation tasks because there's no guarantee that the next person in my job is going to be familiar with Perl, Ruby, and Python, but every unix admin is going to know Bash.

      If all I need to do is start up a job, make sure it created a non-zero length output file, and log a message if it ends with a non-normal return code, bash is simple and easy and has no real drawbacks.

      For anything non-trivial (i.e. a monitoring plugin to do a transaction on our website) than I would use Perl (

    • by mangu ( 126918 )

      Why does anyone still use shell scripts anymore?

      Because they are the simplest and quickest way to do a lot of things one needs to do when using a computer. Try this in python, ruby, or perl:

      the disk is nearly full, find who is the hog

      in bash:

      du -x / | sort -n

      Now do it in another language

      • by hawguy ( 1600213 )

        It's trivial to do it in perl!


        #!/usr/bin/perl

        system("du -x / | sort -n");

        • by grcumb ( 781340 )

          It's trivial to do it in perl!

          #!/usr/bin/perl

          system("du -x / | sort -n");

          As a career Perl hacker, I sympathise, but you're enthusiasm is misplaced in this situation.

          First, system() only gives you the return value of the command you executed, so you haven't got anything useful. Backticks would work, but they're horribly insecure if you're doing variable interpolation.

          Second, a more realistic example would look like this:

          for DIR in `find /home/ -maxdepth 1 -mtime -7 -type d`; do du -sh ${DIR} | grep '\d+G'; done;

          This, too, is easily done in Perl, but why bother when you're just

          • by hawguy ( 1600213 )

            It's trivial to do it in perl!


            #!/usr/bin/perl

            system("du -x / | sort -n");

            As a career Perl hacker, I sympathise, but you're enthusiasm is misplaced in this situation.

            First, system() only gives you the return value of the command you executed, so you haven't got anything useful. Backticks would work, but they're horribly insecure if you're doing variable interpolation.

            That's like saying that the original poster's shell command didn't give him anything useful since it just wrote the output to stdout (i.e. his terminal).

            My perl script did the exact same thing since all system does is fork() and exec(), so the stdout/stdin are inherited by the child process(es). In this case, since there were shell metacharacters in the command line, my system() argument was actually passed onto the shell for execution, so in that respect you're right that I haven't gotten anything useful -

            • It's trivial to do it in perl!


              #!/usr/bin/perl

              system("du -x / | sort -n");

              As a career Perl hacker, I sympathise, but you're enthusiasm is misplaced in this situation.

              First, system() only gives you the return value of the command you executed, so you haven't got anything useful. Backticks would work, but they're horribly insecure if you're doing variable interpolation.

              That's like saying that the original poster's shell command didn't give him anything useful since it just wrote the output to stdout (i.e. his terminal).

              But in shell that's exactly what you need for the next step of processing. In Perl you'd want to capture this in a variable, or split it on newlines to produce an array value, or something. That's... what, backticks? I am no Perl master.

              • by hawguy ( 1600213 )

                But in shell that's exactly what you need for the next step of processing. In Perl you'd want to capture this in a variable, or split it on newlines to produce an array value, or something. That's... what, backticks? I am no Perl master.

                He was debugging a disk space problem and wanted to see what was using the disk space. No need to put it into variables, no need to build an array, he wanted to see where his disk space was going. Sometimes even in perl, you don't want to do any complicated data manipulations, you just want to see the output.

                Though admittedly, there'd be no reason to run his bash commands in Perl, but hey, he asked, so I provided.

                He said this:

                in bash:

                du -x / | sort -n

                Now do it in another language

                Nothing about storing it in variables, nothing about building an in-memory data st

          • It's trivial to do it in perl!


            #!/usr/bin/perl

            system("du -x / | sort -n");

            As a career Perl hacker, I sympathise, but you're enthusiasm is misplaced in this situation.

            "you're" is a contraction. What do you suppose it's a contraction of?

      • You left yourself wide open. Here's my answer:

        #!/usr/bin/perl
        exec("du -x | sort -n");

        Would I use it in place of

        #!/bin/sh
        du -x | sort -n

        No. But it's not something I have to "try" very hard to do in the same number of lines and not many more characters.

    • You listed the options backwards. Most UNIXes (you might be shocked to find that Linux isn't the only Unix variant people use) do not ship with Python, and I do everything I can to avoid having Ruby installed on even my Linux systems. And while I love perl, you are the first person I've heard describe its syntax as sane. :)

    • by Bigbutt ( 65939 )

      Why does anyone still use shell scripts anymore?

      Because I'm a Unix Sysadmin?

      Shell scripting is something I haven't felt the need to do in 5 years.

      I'm guessing you're not a Unix Sysadmin any more?

      If we were interviewing someone who said they hadn't written a shell script in 5 years, I'd have to spend some extra time querying the reasons and then think twice about hiring him. See, we use shell scripts. For init scripts, for simple tasks, for data gathering; loop through 300 systems getting the uptime for instance. Someone we hire would need to be able to perform maintenance on the scripts and hopefully not break an existing

    • by grumbel ( 592662 )

      Shell code is much easier to write then any other language, thats why we type it into our xterms after all instead of Python code. So naturally shell one-liners grow into shell scripts. There is also a mismatch between what Python/Ruby provides and what your shell provides, thus converting shell scripts into Python/Ruby isn't exactly straight forward and its easier to keep things as shell instead of doing a complete rewrite.

    • by jgrahn ( 181062 )

      Why does anyone still use shell scripts anymore? Every major(and most minor) distro ships with python, ruby, and perl either built in or a trivial statement away. These languages give you access to basic OS functions and much more sane syntaxes. Shell scripting is something I haven't felt the need to do in 5 years.

      Then your tasks are different from mine. There are things that can be done much better in a shell script than in Perl or Python. Anything that executes a lot of other programs for example. Anything that pipes them together. I use Perl and/or Python a lot for many things, but shell scripts still have their place. (And if you choose to use bash rather than /bin/sh the language isn't *that* primitive.)

  • This would actually be pretty useful for total noobs (to Bash) like me. I haven't played with programming since 1997 and Fortran. Before that it was C64 Basic. I find that lots of the resources online about Bash scripts are not very good at explaining what the heck is what, syntax and how it all goes together. I can muddle my way through it, but not at the level I like.
  • by prgrmr ( 568806 ) on Friday April 15, 2011 @02:36PM (#35832160) Journal
    First of all, let me remark by saying that shell scripting is something learned more on a need basis than as a tool to solve the main problem. People would seldom write shell scripts as standalone programs

    Seriously? So you write your application's /etc/init.d scripts in something other than bash (or csh if on solaris, or ksh if on aix)? Granted not everyone would want, let alone try, to write 500+ line bash scripts like I occasionally do; but, there are a ridiculous number of 100+ line perl scripts that could have been done in bash or ksh in fewer lines, and with more clarity, and without the overheard of loading dozens of perl modules due to interdependencies among them.
    • csh if on solaris

      Speaking of csh on solaris, I had a devil of a time figuring out why my csh scripts never worked until I realized that I needed to always put a newline character on the last line (the system wouldn't parse the last line without it). I slowly learned to hate csh's oddities as I learned tcsh (and later, [ba]sh).

    • by Bigbutt ( 65939 )

      csh on Solaris? All scripts are generally in /bin/sh on my Solaris systems.

      [John]

  • So the bash fork bomb got popular back while I was at UNH. If you're not familiar with it, it's similar to this: ;(){ :|:& };: (I changed one character so that you dont paste it on recommendation) The way it works is trivial, and it's mystique is only in that it uses punctuation marks in lieu of letters for its own name: make a new function called :, run it and force the output into a new fork of itself in the background; then a final call to the new function. h4rdc0r3 1337.

    So, we had this UNH policy that if you hung a shared unix dev box, you got evicted from CEPS (the college for the engineering/cs kids). They could give you a warning or go straight to evict. Their call.

    I wrote to their head unix admin once, and with some humility, cause I knew they knew this, pointed out that they could just change the system's ulimit values to disallow casual fork bombing. The default system ulimits on the distro back then (still?) allowed a single user to consume all memory. So we saw a couple kids run the fork bomb and they never actually got evicted, cause maybe 40 grand tuition outvotes a cranky unix admin's wanton lust for cruelty.

    Anyways, as a student, my issue was this - set the damned ulimit so that my editor session doesn't get wiped with my homework -- you can't argue for frequent backups when more than 0 seconds of hard work are arbitrarily on the line solved by a simple config change.

    But the UNH unix admin guy replied to me and told me that yeah, he knew about ulimit back when I was in diapers, but he wasn't going to change it up. And a few more times that semester, I lost a couple lines of uncommitted code due to some clown pressing enter on a dare.

    Fork ya later,

  • Comment removed (Score:5, Insightful)

    by account_deleted ( 4530225 ) on Friday April 15, 2011 @02:40PM (#35832196)
    Comment removed based on user account deletion
    • by tnk1 ( 899206 )

      There's a reason we use /bin/sh (Bourne) to write scripts, and it's the same reason we use vi to edit them - mainly it's available on ALL UNIX systems. Despite widespread adoption, bash is not universally available - sorta like EMACS.

      If I stick it in root's cron on, say, an AIX system and it pukes I'm not interested in rewriting somebody's bash script to handle running under sh, csh or ksh. I want it written by its original author in sh. And I don't want to hear about a shebang line (#! /bin/bash) - if I haven't installed bash, it'll still puke.

      That makes good sense if you are writing scripts that you will have the need to run from maintenance mode, but that's a pretty small amount of administrative scripting when it comes down to that.

      However, if you are writing all of your shell scripts with the assumption that you will not be able to access something as widely available on all UNIX platforms as bash, even when those scripts are not needed in maintenance mode and/or make reference to things that wouldn't be available in maintenance mode anyway,

    • > mainly it's available on ALL UNIX systems

      Mainly it doesn't matter since this book is about LINUX shell scripting.

      Besides Bash, a lot of tricks and utilities are only available if you assume a Linux environment.

    • There's a reason we use /bin/sh (Bourne) to write scripts, and it's the same reason we use vi to edit them - mainly it's available on ALL UNIX systems. Despite widespread adoption, bash is not universally available - sorta like EMACS.

      But not all GNU/Linux systems. Gentoo is a prime example. Nano instead of vi. And as sibling stated: almost no GNU/Linux system has true sh, they symlink sh to bash.
      Oh, and don't stick things in a crontab on Mac OS X systems. Mac OS X prefers XML plist files for scheduling and startup.

    • by fnj ( 64210 )

      You, sir, understand the Unix philosophy.

    • Not all scripts are meant to be re-usable.

      I often find myself writing a script directly in my terminal, without going through a text editor. A simple for i in `find the_files_i_want_to_do_something_with | preprocess_the_input`; do what_I_want_to_do_on_those_files $i; done.
      In this particular, I'm just using the shell I happen to be running (bash). I don't have to care about compatibility. Whatever works to get my job done is enough.

      Actually, whenever I want to write a re-usable script, I write it in Python.

  • I've just had a look through the book via Amazon's Look Inside.

    I simply cannot fathom how so many authors manage to get a book published on a subject they don't even master properly. "Shell scripting" is by far the worst in this category. So much that I recommend anyone to run screaming in the other direction when you see mention of "shell scripting" in any title. If it mentions "Linux", it's usually also an excellent indicator of junk. Not to take away from the beauty of the Linux kernel (which obviously has nothing at all to do with shell scripting, but let's ignore that fact).

    I obviously haven't read the book, but when I skim through it and I see failure to quote parameters, failure to recognize the difference between executing a script with /bin/bash in the hashbang and running it by passing it as an argument to sh, and more, I know for a fact that I'm going to be sitting in #bash trying to re-educate poor misguided souls for as long as I can suffer it.

    To those interested in the subject: Do not read this book. Do not read this "Advanced Bash Scripting Guide" mentioned in this review. You will end up writing junk.
    Go see Greg Wooledge's wiki, it's got an extensive FAQ of actually useful issues (http://mywiki.wooledge.org/BashFAQ), it's got a great newbie guide (http://mywiki.wooledge.org/BashGuide), it's got a great cheat sheet (http://mywiki.wooledge.org/BashSheet), and much more. Best of all: Unlike that broken ABS, they're all community supported and unlike this book, the knowledge is free.

    • by turgid ( 580780 )

      What's wrong with the Advanced Bash Scripting Guide at tldp.org?

      It's not perfect, but it will get you along way.

      • The main issue I have is that the "Advanced Bash Scripting Guide" seems to be fascinated with listing every possible way to do the things it covers in bash. But missing from that tutorial is any notion of which of those approaches is the best one in any context. Certain shell constructs are best avoided, in favor of ones that are either more portable to other shells, more resilient in the face of bad data, or easier to maintain. But you get no sense of this from the guide; just a set of ways to hack the

    • by Greg W. ( 15623 ) on Friday April 15, 2011 @03:55PM (#35833226) Homepage

      Go see Greg Wooledge's wiki

      Just not all at once, please.

    • I had been limping long with the Advanced Bash Scripting Guide and Google searches for a while. The Wooledge guide looks like a vast improvement. Thanks.

    • This might be the appropriate place to mention the venerable Unix Power Tools [oreilly.com].

      It goes through most of the common Unix commands (including Bash, but also sort, uniq, awk, sed, etc.). It teaches you about redirection and piping, customizing your shell prompt, xterms, X, remote X, Unix file times and permissions, find/exec, diff, head/tail, grep, vi, emacs, jobs, cron, time, regexes, sed, bash scripting, tar, rcs/cvs, perl/python, /dev, symlinks, tty's, ssh, users/groups.

      In short, everything you ought to know

  • The only interesting thing about this book was to find the author's web site and see how many hoops there are nowadays to get through the Yahoo interview process. I've a friend who managed to get a senior sysadmin role at Yahoo a few years ago who can barely program and has no computer science knowledge whatever - his only previous experience was some ISP admin work, although he was a tremendous suck-up to^W^W^Wgood friends with a few core FreeBSD developers. Anyway, I had the impression that the company wa

Think of it! With VLSI we can pack 100 ENIACs in 1 sq. cm.!

Working...