Slashdot Log In
Bash Cookbook
Posted by
samzenpus
on Wednesday August 13, @01:59PM
from the read-all-about-it dept.
from the read-all-about-it dept.
Chad_Wollenberg writes "Anyone who has used a derivative of Unix over the past 20 years has used Bash, which stands for Borne Again Shell. The geek in all of us makes us want to extend our ability to rule the command line. To truly master a Unix environment, you need to know a shell, and Bash is easily the most popular of them. Any Unix/Linux/BSD administrator knows the power at your fingertips is fully extended by what you can do within the Bash environment, and all of us need the best recipes to get the job done." Keep reading for the rest of Chad's review.
| Bash Cookbook | |
| author | Carl Albing, JP Vossen, Cameron Newham |
| pages | 598 |
| publisher | O'Reilly |
| rating | 9 |
| reviewer | Chad Wollenberg |
| ISBN | 978-0-596-52678-8 |
| summary | A good book for intermediate and above users of Bash |
Enter Bash Cookbook. Properly named for the series of O'reilly books that gives you valuable information on subjects in the form of recipes, this book was refreshing in that it was properly organized, and surprisingly contemporary, even citing Virtualized platforms as a way to try out different OS's for Bash. The book does a good job of pointing out the different operating systems that do run Bash, even citing Cygwin for Windows. They also use the POSIX standard, so that all of the examples are portable across platforms.
Bash Cookbook is by no means for the feint of heart. It seems that the book is meant for intermediate and above users of Bash. However, the first several chapters do a significant job of over viewing basic concepts of Bash navigation and combing simple commands. The book quickly changes gears to complex statements on how to get things done in Bash.
By Chapter 7, Bash Cookbook extends out of Bash commands and begins exploring combining the power of bash scripting with useful command such as grep, awk, and sed. To quote the authors, "if our scripting examples are going to tackle real-world problems, they need to use the wider range of tools that are actually used by real-world bash users and programmers." And that is exactly what they do. This chapter alone gave me the ability to do more in the command line environment simply by explaining the functions of the scripts put forth. That is something that any reader, intermediate to expert, can take from this book. The detailed explanations really do give everyone the ability to learn something about the commands, and the references to additional resources often lead me to the computer, looking up further details.
I found Chapter 11 to be very useful (pun intended) finally grasping some concepts on the find command that have previously escaped me. From Chapter 12 on, the book focuses on writing useful and complex scripts. This is where the book really begins to shine for the Unix enthusiast and system administrator. The scripts found in Chapter 12, and their elaborate descriptions begin to show the true power of Bash scripting, and how much you can automate. Chapter 14 is about securing your scripts, and is a heavy read, but well worth reading for any administrator that would be using their scripts in a production environment.
Just when you think this book has reached its limits, it gives very handy customization examples in Chapter 16 on how to configure and customize Bash. And also goes into common mistakes made by the novice user. Combine all of that with the Appendices for quick reference, and this book has not left my side since it arrived. While I would not recommend this book for the novice user, I would recommend this book to any system administrator that has to work with Unix or Linux. If nothing else, the examples given here are full of good, reusable code to make tasks easier in your day to day functions. Well done.
You can purchase Bash 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.
Bash Cookbook is by no means for the feint of heart. It seems that the book is meant for intermediate and above users of Bash. However, the first several chapters do a significant job of over viewing basic concepts of Bash navigation and combing simple commands. The book quickly changes gears to complex statements on how to get things done in Bash.
By Chapter 7, Bash Cookbook extends out of Bash commands and begins exploring combining the power of bash scripting with useful command such as grep, awk, and sed. To quote the authors, "if our scripting examples are going to tackle real-world problems, they need to use the wider range of tools that are actually used by real-world bash users and programmers." And that is exactly what they do. This chapter alone gave me the ability to do more in the command line environment simply by explaining the functions of the scripts put forth. That is something that any reader, intermediate to expert, can take from this book. The detailed explanations really do give everyone the ability to learn something about the commands, and the references to additional resources often lead me to the computer, looking up further details.
I found Chapter 11 to be very useful (pun intended) finally grasping some concepts on the find command that have previously escaped me. From Chapter 12 on, the book focuses on writing useful and complex scripts. This is where the book really begins to shine for the Unix enthusiast and system administrator. The scripts found in Chapter 12, and their elaborate descriptions begin to show the true power of Bash scripting, and how much you can automate. Chapter 14 is about securing your scripts, and is a heavy read, but well worth reading for any administrator that would be using their scripts in a production environment.
Just when you think this book has reached its limits, it gives very handy customization examples in Chapter 16 on how to configure and customize Bash. And also goes into common mistakes made by the novice user. Combine all of that with the Appendices for quick reference, and this book has not left my side since it arrived. While I would not recommend this book for the novice user, I would recommend this book to any system administrator that has to work with Unix or Linux. If nothing else, the examples given here are full of good, reusable code to make tasks easier in your day to day functions. Well done.
You can purchase Bash 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.
Bash Cookbook
More |
Login
| Reply
The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.

BASH != Bourne Shell (Score:5, Informative)
'sh' is the Bourne shell.
'bash' is the Bourne Again SHell.
They're not the same.
Reply to This
Re:BASH != Bourne Shell (Score:5, Funny)
<begin file A>
#!/bin/bash
perl <<EOP
print "hello world\n";
EOP
<end file A>
<begin file B>
#!/bin/sh
perl <<EOP
print "hello world\n";
EOP
<end file B>
See? Both work, it's so easy!
Reply to This
Parent
Re:Shell as a scripting language... (Score:5, Insightful)
Reply to This
Parent
Re:Shell as a scripting language... (Score:5, Interesting)
The lack of structured data and live objects is a feature, not a bug. The fact that everything is a string, and that everything can be piped between all the different commands means that you can string together commands in new and exciting ways that nobody ever thought was possible. Making all the commands pass around different types of objects means that all the other commands have to be aware of all these other datatypes, and have to know how to handle them.
This is true of textual data as well - you're simply glossing over the complexity of serializing and re-parsing any non-trivial data structure in textual form... You've ignored the fact that for any two tools to work together, their assumptions about the structure with which data is encoded over the stream have to match.
See, if your text-encoded data is simple enough that you can simply choose a character as a field delimiter and another as a record separator, it's easy to split your data into individual records and fields again. It gets a little harder if you want to provide for the possibility that your records may actually contain the delimiter characters (then you're into parsing - at least enough parsing to distinguish between an escaped character and an unescaped one) Setting up the format so you can really encapsulate anything - that reaches the point where it's worth having a tool whose only job is interfacing with this format...
The problem here is that normally when you want to interpret some encoded form of a piece of data, you first translate it into something that's easier to work with. But in BASH (and most CLI shells, I believe) there is no "more convenient form" to which you can readily translate any moderately complex structure. (Consider, for instance, how you would implement an XML parser for Bash - as an external command it simply wouldn't work... it'd have to be done as a Bash plug-in module, and even then its capabilities would be limited. And then suppose you want to filter the parsed data and pass it to another process? You've got to re-encode it, and then the next process has to know how to decode this encoding (probably still XML) as well...
I contend that the "encode everything as a string" mentality was an asset, due to computer limitations in the time period in which the convention started - but these days I think it's pretty limiting.
If you want something with objects and structured data in the shell, then there's MS PowerShell. But maybe there's a reason it hasn't caught on yet.
I think Powershell has been progressing (in terms of popularity, I mean) quite satisfactorily... The reason it hasn't caught on with me, however, is 'cause I want a Unix solution (that is, runs on Unix, and fairly Unix-styled), not a Windows one - and while I agree with the logic behind some of their design decisions (like the verb-noun convention for command names) I don't like the consequences (the language is much too verbose for my tastes...)
I think it's a step in the right direction but not quite what I'm looking for.
Assuming Powershell hasn't been embraced and taking that as a sign that one particular facet of its design was a bad idea is pretty laughable. Any new tool takes time to be adopted - and Powershell is a tool for a fairly small niche - CLI users on Windows.
Reply to This
Parent
Shell as a general-purpose language... (Score:5, Interesting)
True story:
A guy I go to school with (I'm in CS, he's in physics) used to talk about how he was a Bash wizard. Since he was generally talking about writing scripts to submit jobs to a PBS-based cluster, I assumed he meant just in terms of rapidly submitting a large variety of jobs. One day he complains to me that his simulations were slow and wanted me to look at it with him to help him speed them up. So I say fine, send me the file...
He'd written a particle physics Monte Carlo sim using Bash and Linux command line tools (in particular, there were calls to bc everywhere).
Reply to This
Parent
Re:Shell as a general-purpose language... (Score:5, Funny)
He'd written a particle physics Monte Carlo sim using Bash and Linux command line tools (in particular, there were calls to bc everywhere).
Well, I, for one, welcome our new particle physicist bash programming overlord!
Reply to This
Parent
Re:BASH != Bourne Shell (Score:5, Informative)
In Ubuntu since edgy, sh has been symlinked to dash instead. This allowed for a much faster boot while breaking all the "sh" scripts that used bash-specific syntax.
There was a bunch of whining about it when it happened but I think everyone fixed their scripts and shut up.
Reply to This
Parent
Re:BASH != Bourne Shell (Score:5, Funny)
I'd stick a rocket up the arse of anyone who sent me a product that wouldn't install because of a basic, newbie mistake like that.
You'd need a lot of rockets. In my experience, this sort of error is very, very common.
Reply to This
Parent
Re:BASH != Bourne Shell (Score:5, Informative)
Reply to This
Parent
Re:BASH != Bourne Shell (Score:5, Informative)
No, it doesn't. There are a couple of changes, like ~/.bashrc is not read, but mostly it stays as-is. Basically, if you invoke bash as sh, AND stay inside the sh syntax/commands, then bash works like sh.
-sh-3.00$ /bin/sh
sh-3.00$ help bind
bind: bind [-lpvsPVS] [-m keymap] [-f filename] [-q name] [-u name] [-r keyseq]
[-x keyseq:shell-command] [keyseq:readline-function or readline-command]
Bind a key sequence to a Readline function or a macro, or set
a Readline variable. The non-option argument syntax is equivalent
to that found in ~/.inputrc, but must be passed as a single argument:
bind '"\C-x\C-r": re-read-init-file'.
[...]
sh-3.00$ echo $PS1
\s-\v\$
sh-3.00$ export PS1='myprompt '
myprompt export PS1='\s-\v\$ '
sh-3.00$ exit
exit
-sh-3.00$
Here, bind and PS1 (help maybe?) are both in bash but not sh.
Reply to This
Parent
"feint" of heart? (Score:5, Funny)
So, what, does this refer to people who act like they're going to rip your heart out of your chest, only it all turns out to be a ruse so they can kick you in the balls?
Reply to This
It's for people like me. (Score:5, Interesting)
Who already own "sed and awk" and buy a book that is supposedly about Bash scripting only to find out that the advanced section replicates what is in the sed and awk book. Which is very annoying.
Not that it's a bad book. I just believe that it should have been more focused on Bash only scripting.
If you want to learn about sed and awk, buy the sed and awk book. If you want to learn Bash scripting, there are a LOT of more useful sites online.
Reply to This
Parent
Re:It's for people like me. (Score:5, Insightful)
Reply to This
Parent
Bourne-Again Shell (Score:5, Informative)
Bourne Again Shell [gnu.org], not Borne.
Reply to This
Re:Bourne-Again Shell (Score:5, Funny)
Seriously now, this is like posting a LOTR review by someone who thinks it was written by RJ Tokelen. Or a Star Trek review from a fan of "the late Rod N. Barry".
You gotta love our editors!
Anyway, back to my review of Dark Night... Chris Nolon did it again!
Reply to This
Parent
And faint of heart (Score:5, Funny)
And it's "faint of heart" not "feint of heart".
And it would be "overviewing basic concepts" not "over viewing basic concepts" if "overview" were a verb.
I made it as far as:
before threwing in the trowl.
--MarkusQ
Reply to This
Parent
What about the Advanced Bash Scripting Guide? (Score:5, Informative)
Reply to This
Nice review, but I don't understand something. (Score:5, Interesting)
I may even buy the book based on the review.
Leaving aside stuff like not for the feint of heart, which is just poor editing, what the hell does I found Chapter 11 to be very useful (pun intended) mean?
Maybe it's the ultimate meta-pun, where there was no pun in the first place, but the author pointed out that one was intended, so one was slipstreamed into the statement.
Reply to This
Re:Nice review, but I don't understand something. (Score:5, Funny)
Okay, somebody had to say it.
Reply to This
Parent
Unix you say.. (Score:5, Informative)
I run into alot more sh, ksh, csh, and tcsh.
Reply to This
Bash cookbook? (Score:5, Funny)
Well, ok... Cookbook sucks!
Oh, did I parse that wrong?
Reply to This
Feminists don't need this book (Score:5, Funny)
They can just enter "man bash" on the command line
Reply to This
Not the only choice (Score:5, Insightful)
I loved Bash (and was the maintained of the FreeBSD port of the Bash tab-completion for a while), but gave it up forever about a week after I tried Zsh [zsh.org]. For me, it's like "Bash done right", from associative arrays for easy scripting to tab-completion that's fast and doesn't pollute the namespace with thousands of tiny functions:
Which leads me to ask: has anyone tried Zsh but then gone back to Bash? If so, why?
Reply to This
Re:BOURNE (Score:5, Funny)
It's the Born again Bourne Again shell. Now with more Jesus.
Reply to This
Parent
Re:Holding Out (Score:5, Funny)
Do you really want a shell that runs out of memory and starts killing all of your processes?
Reply to This
Parent