views:

288

answers:

7

I'd like to brush up on my knowledge of Shell scripting with Bash for a job interview Monday.

What would the preferred book be for someone with an existing knowledge looking to review the topic?

+2  A: 

bash Cookbook, by Carl Albing, JP Vossen & Cameron Newham

O'Reilly ISBN 10: 0-596-52678-4

pavium
A: 

This is an excellent free on-line resource:

Advanced Bash Scripting

ennuikiller
"The Linux Documentation Program"... Is it horrible that I thought it might have stood for "Too Long, Didn't Print"?
Matthew Scharley
I had to unlearn most of what I learned from the ABS.
guns
@guns: it's really not that bad!
ennuikiller
@ennnuikiller: not that bad, if you're not good enough a shell scripter to notice the horrible flaws and bad practices. Which is EXACTLY why it should not be used for newbies as a learning resource.
lhunath
@Ihunath well its not as if I studied the whole document. The times I needed a reference source it seemed adequate. While shell scripting is not my primary language I seem to get by pretty well :)
ennuikiller
+9  A: 

The best reference for someone with some experience would be BashGuide by Lhunath.

It teaches current best practices for modern Bash shells:

  • using [[ $var ]] vs [ $var ] or test $var
  • proper use of grouping techniques: { command1 && command2; } || command3
  • use of here strings: cmd <<< foo vs echo foo | cmd
  • parameter expansions: var=foobar; echo ${var//o/O} => fOObar
  • brace expansions: for i in {1..10} (instead of using seq or jot)
  • solid basics: if grep foo file vs if [[ $(grep foo file) -eq 0 ]]

It would be wise to avoid the often-referenced Advanced Bash Scripting guide; most of the examples there are misleading or antiquated.

BashPitfalls and BashFAQ are also particularly helpful if you are already very familiar with POSIX Bourne shell scripting.

Finally, if you're not averse to concise documentation, go straight to my favorite source: man bash. It's quite readable if you've been using a shell for some time. And if you need to maintain compatibility with older versions of bash, Chet Ramey keeps a version history here: http://tiswww.case.edu/php/chet/bash/CHANGES

guns
didn't know the advanced bash scripting guide was misleading or antiquated! There are some typos, but overall I think it is a good resource!
ennuikiller
Well, I remember that it encouraged overuse of temp files, did not regularly quote variables, and never concisely explained how to elegantly work around subshells.I agree that it wasn't bad ~1999, but bash has progressed quite a bit since then. The entire guide needs to be overhauled in a consistent modern style.
guns
+1 for Greg's BashGuide, +1 for ABS "misleading or antiquated", +1 for BashPitfalls and BashFAQ, another +1 if you had mentioned `$()` vs. backticks, another if you had mentioned http://mywiki.wooledge.org/ParsingLs
Dennis Williamson
Beside the fact that the BashGuide is Lunath's - yes, this is a really sane answer. There is hope, between all the bad code you find :)
TheBonsai
@TheBonsai: Changed attribution to Lhunath. Thanks for pointing that out.
guns
+1  A: 

Type info bash on the command prompt.

the bash reference is one of the best info you can read on bash. Those who don't read it deserves a spanking
The reference is not a tutorial, it's a reference.
TheBonsai
did you read the post? OP has experience and he is reviewing it! A reference IS better than a tutorial.
In that way yes. It's better.
TheBonsai
A: 

There's nothing like going directly to the Bash maintainer.

Here's his FAQ.

And an online version of the info file.

Dennis Williamson
A: 

I used this as a reference book when I learned BASH scripting. I thought it was extremely useful, even after the learning period

inspectorG4dget
A: 

I usually wouldn't suggest man pages, however in this case typing 'man bash' not a bad option especially worth a quick read before you do a technical test. I'd also recommend the o'reilly sed & awk book (http://www.amazon.com/sed-awk-2nd-Arnold-Robbins/dp/1565922255), as I guess if you're working in bash, awk will be frequently used. Also http://www.vectorsite.net/tsawk.html is a good place a start with awk.

Jamie