Bash Cookbook 278
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.
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 | |
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 |
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 != Bourne Shell (Score:5, Informative)
'sh' is the Bourne shell.
'bash' is the Bourne Again SHell.
They're not the same.
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!
Shell as a scripting language... (Score:2)
Now, here's what I'd like to know...
Are you serious here, showing that both shells support useful features, or are you being facetious, showing that both shells are merely acceptable stepping-stones to run Perl code?
I love CLIs but my feeling on most of them is that they're more than a little archaic - the lack of any non-trivial datatypes (and particularly the lack of support for passing structured data or live objects between shell processes) makes it needlessly difficult to get things done - I believe th
Re:Shell as a scripting language... (Score:5, Insightful)
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.
Re: (Score:3, Insightful)
Dude, it is upto the programmer to format the data properly, including any escaping when piping strings from one proggie to another.
Shell scripts aren't supposed to replace more robust programming languages. I think it silly to want to parse XML via shell scripts, BUT, a shell script could pull useful data from an XML file.
So let me stat
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).
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!
Re: (Score:2)
Damn, that is hardcore scripting!
I bow to the guys geekitude!
Re: (Score:2)
Hey just throw more hardware at it right? His time on the hours he'd spend writing it in a faster language are worth more than the cost of a few new boxes, natch.
Re:Shell as a general-purpose language... (Score:4, Funny)
Bash scripting is dangerous. I wrote a client script to test a Helix multimedia server, once - we're talking millions of socket connections purely from a shell here (not even using netcat), and the professor gave us a B+ for the project. Needless to say, I wrote another script that summer, much smaller and more elegant, that thrashed and brought down the clueless bastard's website.
Parents: talk to your kids about Bash, before someone else does.
Re:Shell as a scripting language... (Score:4, Informative)
From what I've seen (not used it) the new Windows PowerShell (Monad) is designed around "piping" data between apps that actually exchange .Net objects, including lists, maps, etc. of objects -- rather than character streams. There seem to be generic commands that provide sql-like "select / where" filtering clauses, etc., too. You might explore that, see if it fits your needs. It looks awfully verbose to me though, I'd have to find a way to set aliases for most everything. Just a thought.
Re: (Score:2)
From what I've seen (not used it) the new Windows PowerShell (Monad) is designed around "piping" data between apps that actually exchange .Net objects, including lists, maps, etc. of objects -- rather than character streams. There seem to be generic commands that provide sql-like "select / where" filtering clauses, etc., too. You might explore that, see if it fits your needs. It looks awfully verbose to me though, I'd have to find a way to set aliases for most everything. Just a thought.
Yeah, I learned about Monad a few years back, and have tried Powershell, briefly anyway - it's definitely interesting but various things about it don't really suit my tastes. I'm trying to come up with something that does.
Re:Shell as a scripting language... (Score:4, Funny)
What are these "datastructures" you speak of?
Re: (Score:2)
Most data translation projects don't need advanced data structures to get the work done. This common misconception is responsible for a great deal of the software project failures over the last few decades.
I'm just talking about basic data structures here - support for anything beyond strings or text streams. Shell programming has become mired in translation steps. Scripting languages let you avoid all that because the language provides data structures and objects, as well as a reasonable set of baseline data types, which modules written in the language can work with.
Some shells support some data structures and containers, but I think Powershell is the only one right now that can actually pass these between
Re: (Score:2)
Yeah, old-school bash is about as fun as doing trivial tasks in C. And I love C. But still...
I use bash and a little folder in my $PATH as a more robust solution to alias-ing.
But for anything over 1 or 2 lines, calling shell utilities from Ruby is about a hundred million times easier.
I can't keep that archaic syntax in my head for more than a day at a time.
Re:Shell as a scripting language... (Score:4, Informative)
Re: (Score:3, Informative)
$ ls -l
lrwxrwxrwx 1 root root 4 Mar 10 2006
Re:BASH != Bourne Shell (Score:4, Informative)
Except for the fact that sh is generally symlinked to bash on Linux systems:
True. But if bash is invoked as 'sh', it works like sh.
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.
Re: (Score:3, Insightful)
This just bit me in the ass a couple weeks ago. Debian/Ubuntu don't symlink to bash, which is what I'd assumed. They symlink to "dash" -- a stripped-down shell where stuff you expect to work doesn't.
For the life of me I couldn't figure out why my perfectly valid bash one-liner in my crontab wouldn't work. Some Googling and cursing Debian later, and /bin/sh -> /bin/bash, and my cron jobs are working as expected.
Now, someone can disagree with me here, and I know you will. The stated purpose of this change
Re: (Score:3, Funny)
Re: (Score:3, Insightful)
Re: (Score:2, Informative)
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.
Re: (Score:3, Insightful)
That fact does cause a lot of problems with poorly-written third-party scripts, though. I spent two full days scratching my head over why I couldn't run the IBM Rational Software Architect installation program on my Ubuntu box, even though it had worked just fine on Debian. Finally I realized that the installation script used BASH features, but tried to run under /bin/sh.
That's just one example, and it's the installer that's at fault, not Ubuntu, but I've run into enough of them that I make a habit of c
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.
Re:BASH != Bourne Shell (Score:5, Informative)
Re: (Score:2, Informative)
It doesn't say they're the same.
However, it's "Bourne Again SHell."
Re: (Score:2)
It doesn't say they're the same.
That's right. But it does imply that they're the same.
"Anyone who has used a derivative of Unix over the past 20 years has used Bash, which stands for Borne Again Shell."
The implication that 'bash' has been shipping with the majority of UNIX-like operating systems for 20 years betrays the submitter's failure to distinguish between 'sh' and 'bash'.
Hence with the pointing out that they're not the same.
Re: (Score:2)
Re:BASH != Bourne Shell (Score:4, Informative)
"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?
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.
Re: (Score:3, Insightful)
Re: (Score:2)
That just shows ignorance of how much power exists within bash without using sed or awk. It also shows a lack of understanding of how powerful each sed and awk are as individual programs (or language, in awk's case).
You can write some substantial software in awk, and in bash, or in a combination of both, or using sed.
Of course, mentioning 'make' in a book on C programming makes sense, but not realizing how powerful make is is probably a result of how people associate it with programming only.
(example: I ha
Re:It's for people like me. (Score:5, Insightful)
Re: (Score:3, Funny)
Dude, seriously? Where? Cool!
Oh, wait, you were being sarcastic. Dammit. Don't get my hopes up like that.
Re:It's for people like me. (Score:5, Funny)
A good analogy is like a car.
No. A good analogy is like a metaphor.
Re: (Score:2)
Over viewing? Is that viewing too much? Combing simple commands? I could go on, but I can't go on.
Bourne-Again Shell (Score:5, Informative)
Bourne Again Shell [gnu.org], not Borne.
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!
Re: (Score:2, Funny)
Are you saying the poster had a problem with The Bourne Identity [imdb.com]?
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
What about the Advanced Bash Scripting Guide? (Score:5, Informative)
Re: (Score:2, Insightful)
even though there is a lot of free info, some people like a hard copy of something.
yeah, you could print the same info, but it is not bound, etc.
BOURNE (Score:2)
It's not " Borne Again Shell", but "BOURNE Again Shell".
Stephen Bourne created sh from which bash is derived.
Re:BOURNE (Score:5, Funny)
It's the Born again Bourne Again shell. Now with more Jesus.
Re: (Score:2, Funny)
Crackers or wine?
Re: (Score:2, Funny)
Re: (Score:2)
hehe. nice trolling at the end. let me add fuel to the fire and contend that since Perl became ubiquitous, shells have lost most of their programming importance.
Bourne shell (Score:2)
:
echo "I'm an old Bourne Shell"
echo "Early on the first line was a colon to indicate a bourne shell"
echo "And that was before the convention of #!/bin/sh"
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.
Re:Nice review, but I don't understand something. (Score:5, Funny)
Okay, somebody had to say it.
Re: (Score:2)
I think he meant, uh, what's that thing that spells the same backwards as forwards? A palindrome.
Re: (Score:2, Informative)
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.
I think he's actually referring to Chapter 9 which is entitled "Finding Files: find, locate, slocate" hence the pun on "found".
Re: (Score:2)
Thank you. I understand (no likey!) it now.
Re: (Score:2)
Re: (Score:2)
http://oreilly.com/catalog/9780596526788/toc.html [oreilly.com]
Perhaps the author intended to write, "...to be very timely", realised that made no sense, but left in the aside?
Re: (Score:3, Informative)
He FOUND chapter 11 (which is about FIND) useful. There's the pun. You had to read past the bit talking about the pun to get it.
Re: (Score:3, Informative)
Unix you say.. (Score:5, Informative)
I run into alot more sh, ksh, csh, and tcsh.
Re: (Score:2, Informative)
As a BSD user ... I run into alot more sh, ksh, csh, and tcsh.
Haven't they heard the news in the BSD camps? Scripting in csh is considered harmful. [faqs.org] ;)
/bin/sh to its limits first. I even had it emulating expect for one task, sandwiching telnet between two scripts where the later sent
In all seriousness, having scripted in both, I would consider bash more powerful than ksh, and I avoid csh/tcsh scripting for some of the (still valid) reasons listed in the legendary tome linked above.
(Although, if performance isn't an issue, I usually attempt to stretch good old
Re: (Score:2, Informative)
ksh is far more powerful than bash. ksh93 has associative arrays, floating-point arithmetic, and coprocesses, just to name a few of the features missing in bash. In general, I've found that anything I could do in bash I could do in ksh.
Re: (Score:2)
Also on Cygwin and the Debian GNU/Hurd system, which is not Linux.
FYI, Cygwin is intended to be a Linux-like environment on top of Windows.
Bash cookbook? (Score:5, Funny)
Well, ok... Cookbook sucks!
Oh, did I parse that wrong?
Bash has been my favorite for 12 years (Score:4, Informative)
Bash takes Bourne Shell scripting (which was always more powerful than Csh scripting), and combines it with Csh's and Tcsh's best interactive features (! expansion, arrow history, tab completion, etc.).
The last time I saw people try to have a different paradigm with *NIX shells was with the 'rc' and 'es' shells of the 1990s, which was an attempt to introduce functional programming to the shell. Both shells stopped being actively developed before they were full featured (they never had job control, for example).
More recently, there is a new shell out there called the 'fish' shell, which I tried and didn't like. I don't like its requirement to have everything in a bunch of colors; a true *NIX shell, in my opinion, should not try and make everything colorful (I also despise ls with colors).
Looks like ksh finally was open sourced, but by then Bash had become the standard shell you're guaranteed to have in just about any Linux distribution (exceptions being tiny distributions which use Busybox for everything).
More information, of course, is on the Wikipedia. [wikipedia.org].
Re: (Score:2)
In my experience, any ksh script would run under bash. It was my impression that bash was a catch-all, taking the better ideas from Korn and Bourne.
Re: (Score:2)
One key issue is that systems on boot may not have access to all the libraries that make bash a nice human interface. A core system needs a shell that uses no shared libraries at all and does only simple things to start up programs (like a real shell)... If all that can be kept in nice clean text files that include #!/bin/sh to indicate that they won't be doing anything complicated, then it makes it much easier for developers. While I love to use bash, I wouldn't ever consider if for the rc scripts or sin
Re-usable libraries (Score:3, Insightful)
I do a lot of work in bash. I'm a Linux administrator by trade, so I think in bash all day long. For my company I've developed a set of bash libraries that we call the BPE. These libraries implement a hashmap, stack, linked list, MySQL API, SQLite API and all sorts of other useful things that one doesn't want to re-invent for every script. I'm in the process of writing man pages for the several libraries right now, and I think I'll sourceforge the project when the mans are complete. It's great to be able to begin a new script when a hashmap might be useful, and be able to do something like:
$USE_BPE
use "hashmap"
hm_create "myMap"
hm_set "myMap" "key" "value"
value="$(hm_lookup "myMap" "key")"
echo "$value"
In short, if organized correctly, bash can be used where a senior sysadmin would normally reach for perl or python. This is often helpful when your juniors have a good grasp of bash, but aren't very strong in other languages.
Re: (Score:3, Insightful)
That sounds pretty neat and all, but wouldn't you be better served training people on a language which has these constructs built in? The juniors are still having to learn new programming syntax--only instead of learning Perl, they're learning something that's not used anywhere else in the world.
Is this a way of enforcing loyalty? :)
Re: (Score:2)
Doing advanced things in bash is a personal hobby mine, and if it proves useful to other admins and the company as well, than that's just a bonus.
Re: (Score:2)
They're learning the syntax of your library. They could be learning the syntax of Perl. They could learn both, but they're duplicating effort then.
I'm not knocking making the libraries itself, but it just seems like time spent learning your library (for the job) could be spent learning something which is more universally used.
Re: (Score:2)
Unless you leave or are hit by a bus, and then some poor slob has to come in and reverse-engineer all your cleverness to figure out how to keep your company's systems working.
If it's a personal hobby of yours, tinker with it at home. Don't be forcing everybody you work with to take up your hobby too.
Re: (Score:3, Informative)
In short, if organized correctly, bash can be used where a senior sysadmin would normally reach for perl or python. This is often helpful when your juniors have a good grasp of bash, but aren't very strong in other languages.
You mean it makes it possible to use the wrong tool for the job, in order to avoid a little training.
No offense, but that's a *really* terrible idea.
Re: (Score:2)
...particularly because they will likely move to another job someday and these libraries will no longer be available.
Right tool for the right job is a better skill to learn.
Re: (Score:2)
Another morbidly obese "programming" book (Score:3, Insightful)
598 pages for a book on a shell? Oink!
A little plastic cheat sheet would be far more useful. The important thing is to get the basic ideas and the syntax. That requires a small, tightly written book. In an oinker of a book, the concepts get lost in the verbiage.
Re: (Score:2)
It could be argued that Bash has more language features than many programming languages.
Bash is a huge and very powerful system for both shell work and programming work. The programmable tab-completion being one of my favourites, spell checking is fun too, although I still prefer tcsh's syntax.
Review of BASH COOKBOOK (Score:3, Interesting)
Chapter 1, "Beginning bash" covers what a shell is, why you should care about it, and then the basics of bash including how you get it on your system. The next five chapters are on the basics that you would need when working with any shell - standard I/O, command execution, shell variables, and shell logic and arithmetic. Next there are two chapters on "Intermediate Shell Tools". These chapters' recipes use some utilities that are not part of the shell, but which are so useful that it is hard to imagine using the shell without them, such as "sort" and "grep", for example. Chapter nine features recipes that allow you to find files by case, date, type, size, etc. Chapter 10, "Additional Features for Scripting" has much to do with code reuse, which is something you find even in scripting. Chapter 11, "Working with Dates and Times", seems like it would be very simple, but it's not. This chapter helps you get through the complexities of dealing with different formats for displaying the time and date and converting between various date formats.
Chapter 12, "End-User Tasks As Shell Scripts", shows you a few larger though not large examples of scripts. They are meant to give you useful, real world examples of actual uses of shell scripts beyond just system administration tasks. Chapter 13, "Parsing and Similar Tasks", is about tasks that will be familiar to programmers. It's not necessarily full of more advanced scripts than the other recipes in the book, but if you are not a programmer, these tasks might seem obscure or irrelevant to your use of bash. Topics covered include parsing HTML, setting up a database with MySQL, and both trimming and compressing whitespace. Chapter 14 is on dealing with the security of your shell scripts. Chapters 15 through 19 finish up the book starting with a chapter on advanced scripting that focuses on script portability. Chapter 16 is related to the previous chapter on portability and is concerned with configuring and customizing your bash environment. Chapter 17 is about miscellaneous items that didn't fit well into any other chapter. The subjects include capturing file metadata for recovery, sharing and logging sessions, and unzipping many ZIP files at once. Chapter 18 deals with shortcuts aimed at the limiting factor of many uses of bash - the typing speed of the user and shortcuts that cut down on the amount of typing necessary. The final chapter in the book, "Tips and Traps", deals with the common mistakes that bash users make.
All in all this is a very handy reference for a vast number of the tasks that you'll come across when scripting with the bash shell along with well-commented code. Highly recommended.
Obligatory. (Score:4, Funny)
http://xkcd.com/149/ [xkcd.com]
Re: (Score:2)
http://xkcd.com/234/ [xkcd.com]
Holding Out (Score:3, Funny)
I'm still waiting for jbosh, the Jason BOurne SHell, to be released. I hear it can really kick some ass.
Re:Holding Out (Score:5, Funny)
Do you really want a shell that runs out of memory and starts killing all of your processes?
Re: (Score:2)
Or even worse...after finishing off the processes, it goes after the kernel leading the whole thing.
Re: (Score:2)
C'mon, moderators...this is funny. Definitely the best of the Jason Bourne-related jokes.
If we only had Chad 5 years ago! (Score:2)
Anyone who has used a derivative of Unix over the past 20 years has used Bash
Wow, we could have avoided the entire SCO since AIX is not a derivative of UNIX.
To Serve Webpages (Score:4, Funny)
It's a cookbook!!!
But can it grill cheese? (Score:2)
If I could write me a script that can make me a grilled cheese sandwich and I would very happy.
Re: (Score:2)
If you upgrade from Girlfriend 4.0 to Wife 2.0, you just might be able to do that. Just keep in mind that Wife 2.0 is more expensive in the long run and more likely to give you 403s. The cost of uninstallation if she finds Girlfriend 5.0 running in the background can be life ruining. But if you give Wife frequent upgrades, i hear it can be quite wonderful.
Child processes (Score:2)
My wife 1.0 beta (way past the alpha years) recently spawned a child process. She takes some resources, but so far the experience has been well worthwhile.
Hmm, maybe I can try again to get her to cook/code me some grilled cheese. I know she has the algorithm and the resources, but she never seems to run that code.
Standard Unix Shell? (Score:3, Insightful)
Bash is a fine shell, but it's certainly not the standard on Unixen today. Most versions of Unix still have the Korn/Posix Shell as the most common shell. This is certainly true in Solaris, HP-UX, and AIX. The BSD's typically don't use Bash, and favor more traditional, light-weight shells. However, some versions may package Bash in their distributions.
Bash is really only the common default shell on Linux, from what I have seen. Things learned for Bash have similar syntax in other shells, but teaching newbies that Bash is the standard shell is a very bad, Linux-centric idea that leads to Bash-isms (people trying to use Bash-specific features in other shells).
Feminists don't need this book (Score:5, Funny)
They can just enter "man bash" on the command line
4NT & Bash - better & worse ... (Score:2)
I still miss the directory history (Ctrl-PageUp/Dn) from 4NT. I see one person does too and came up with solution [linuxgazette.net]
Small Warning for Ubuntu users: (Score:3, Informative)
POSIX Standard? Then its not "Bash" (Score:4, Insightful)
So if the book and examples limit themselves to the POSIX subset of bash's capabilities and don't go into the GNU extensions, is the book really about "bash"? It sounds like the book could be called "UNIX shell cookbook" (oops already done) or "Ksh Cookbook" just as much as "Bash Cookbook". But of course, bash is the Linux default and Linux is hot while Unix is passe.
I always thought it was the gnu extensions above and beyond POSIX (while staying backwards capatable with POSIX) that make the gnu tools like bash and gawk so much (allegedly) better than ksh and awk.
BTW, I use bash because it is the default on most linux systems so I am familiar with it. Bash is the very first thing I install on BSD or Solaris systems and then I set it as my login shell. It's actually really rare that I need to call on the gnu extensions, so I could probably be happy with pdksh just as well.
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?
Re:Not the only choice (Score:4, Informative)
Coloring the prompt? That was the "gee whiz!" moment that made me switch permanently. From my .zshrc:
See how all the colors are defined in an associative array, like ${fg[green]} gets you a green foreground? Say I'm in the directory "/usr/share/media/music/albums/Pink Floyd - A Momentary Lapse of Reason". As a regular user, my prompt looks like:
My name@host is green, the time is blue, and the path is red. The smiley face is green. Now, if I'm root:
My name@host is red now, and the prompt char is "#" instead of "$". But what if I run a command and it fails?
The green smiley face is now a red frowney face. Someone suggested a "big" prompt like that, and once I got used to it, I love it. It's very easy to see where command output stops and the next command starts, and the whole green smile vs. red frown thing is an instant visual indicator of a command's results (which sometimes isn't obvious, say if you're redirecting stderr to /dev/null). Sure, I could have done something similar in Bash, but I guarantee it would've been a whole lot less readable. I did that as an experiment to learn Zsh scripting, and I haven't deliberately used Bash since then.
Re: (Score:3, Interesting)
You don't have tab-completion enabled. I don't mean as in complete-the-filename but as in complete-the-command-arguments. For example, in Bash and Zsh with completion enabled, you can enter ifconfig <tab> and it will complete the interface name, or ssh -o<tab> to get a list of options that can be set (and then go on to tab-complete their possible values).
I will never again voluntarily use a shell that doesn't support this.
Re: (Score:2)