DonationCoder.com Forum

Other Software => Developer's Corner => Topic started by: ewemoa on July 04, 2011, 10:20 PM

Title: Bourne / Bash Shell Scripting Resources
Post by: ewemoa on July 04, 2011, 10:20 PM
Started to work through:

  Steve's Bourne / Bash shell scripting tutorial (http://steve-parker.org/sh/)

[ You are not allowed to view attachments ]

Encountered this associated quote:

Doug Kramer (Java, Google.com) says:
"When I started writing CGI script in Bourne shell on the Java team at Sun, I scoured the Internet for a good tutorial and used Steve Parker's guide, which I really like. Now that I've moved to Google and switched to Linux and bash, I've decided to use it as the basis for an in-house introductory course on bash scripting here at Google for our tech writers. I highly recommend it as accurate and written at the right level, plus it includes a useful reference"

CGI scripts in Bourne shell?  Doesn't sound terribly pleasant!

Not a huge fan of shell scripting, but figured it couldn't hurt to be able to read / understand existing code.

Any one have any related favorite resources?
Title: Re: Bourne / Bash Shell Scripting Resources
Post by: MilesAhead on July 04, 2011, 11:42 PM
I never got into CGI except in the most superficial way(like finding out what it is.)  On Windows the best use I found for bash was to enable use of Linux utilities on Win32.  There are stand-alone exe ports of Linux tools for Win32 but you can really string the commands together out of a bash shell in Windoze.  You can do all those cool command substitute tricks with "find" results etc..

By using the bash shell you side step many of the problems such as cmd.exe eating characters that Linux commands use for special purposes.

One resource may be the bargain bin if you have a brick & mortar computer book store nearby.  Since bash is a superset of sh shell, many of the old example sh scripts still work.  I used to have a $9 "in a nutshell" book with many example sh scripts.. but I can't seem to find it to get the exact title.

For me a rudimentary knowledge of bash was required to control Linux startup.  If you are on a Linux server such as Apache then it couldn't hurt to know some bash.  I looked on some of the online book sites but didn't see a cover that looked like my nutshell book. I guess my info is dated. But with unix based systems esp. old scripting code often still works with a couple of tweaks.  The basic system doesn't change all that much. Most of the scripts for the system are still under /etc etc.. :)

Title: Re: Bourne / Bash Shell Scripting Resources
Post by: Edvard on July 06, 2011, 05:44 AM
Start small, work your way up.
The last two links I have printed hard copies of:

Getting Started with BASH (http://www.hypexr.org/bash_tutorial.php) by Scott Rippee:
http://www.hypexr.org/bash_tutorial.php

BASH Programming - Introduction (http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO.html) by Mike G
http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO.html

Advanced BASH Scripting (http://www.tldp.org/LDP/abs/html/) by Mendel Leo Cooper:
http://www.tldp.org/LDP/abs/html/

BASH Reference Manual (http://tiswww.case.edu/php/chet/bash/bashref.html) by Chet Ramey and Brian Fox:
http://tiswww.case.edu/php/chet/bash/bashref.html

 :Thmbsup:
Title: Re: Bourne / Bash Shell Scripting Resources
Post by: ewemoa on July 06, 2011, 07:45 PM
Thanks for the comments and suggestions  :Thmbsup:

The Learn About Bash Scripting section (http://www.hypexr.org/bash_tutorial.php#script) of the suggested Getting Started with BASH (http://www.hypexr.org/bash_tutorial.php) turned up "Bash by example..." (3 parts).  Perhaps somewhat in line with "starting small", am considering "Part 1" as an entry point before attempting some of the suggestions :)

FWIW, I found alternate (possibly updated but not maintained) versions at:


Some headers:

Part 1 (http://www.gentoo.org/doc/en/articles/bash-by-example-p1.xml)
  Introduction
  You're already running it
  You're already using it
  Bash confusion
  Environment variables
  Chopping strings overview
  Command substitution
  Chopping strings like a pro
  Applying string chopping
  if statements
  Next time

Part 2 (http://www.gentoo.org/doc/en/articles/bash-by-example-p2.xml)
  Accepting arguments
  Bash programming constructs
  Conditional love
  String comparison caveats
  Looping constructs: "for"
  Shell arithmetic
  More looping constructs: "while" and "until"
  Case statements
  Functions and namespaces
  Namespace
  Wrapping it up

Part 3 (http://www.gentoo.org/doc/en/articles/bash-by-example-p3.xml)
  Enter the ebuild system
  Why bash?
  Build process review
  Generalizing the code
  Adding functionality
  Modularizing the code
  Configuration files
  Wrapping it up

Looks like part 3 may be gentoo-specific...
Title: Re: Bourne / Bash Shell Scripting Resources
Post by: MilesAhead on July 06, 2011, 09:27 PM
Are you running a Linux system?  If so look through the start up scripts in /etc and see how they do what they do.  The XWindow manager applets usually just pass some params to one of those scripts.
Title: Re: Bourne / Bash Shell Scripting Resources
Post by: 40hz on July 06, 2011, 09:41 PM
If you don't want/need to restrict yourself to online and/or free resources, check out this book (http://www.amazon.com/Practical-Guide-Commands-Editors-Programming/dp/0131367366/ref=sr_1_6?ie=UTF8&qid=1310005957&sr=8-6).


[ You are not allowed to view attachments ]


IMHO the single best $29 (via Amazon) you'll ever spend if you want to start working with the shell.

Combine it with a copy of the UNIX and Linux System Administration Handbook (4th Edition) (http://www.amazon.com/UNIX-Linux-System-Administration-Handbook/dp/0131480057/ref=pd_sim_b_3) (about $43 USD) and you'll have 85-90% of all the technical info you'll ever need to effectively work within the "nix" environment.

 :Thmbsup:

Title: Re: Bourne / Bash Shell Scripting Resources
Post by: ewemoa on July 07, 2011, 03:42 AM
look through the start up scripts in /etc and see how they do what they do.
Sounds like a potentially useful source of real-world example code.  Thanks for the tip  :Thmbsup:
Title: Re: Bourne / Bash Shell Scripting Resources
Post by: ewemoa on July 07, 2011, 03:49 AM
If you don't want/need to restrict yourself to online and/or free resources, check out this book (http://www.amazon.com/Practical-Guide-Commands-Editors-Programming/dp/0131367366/ref=sr_1_6?ie=UTF8&qid=1310005957&sr=8-6).
I see that bits of this book are available for preview via:

  http://www.sobell.com/CR2/index.html (http://www.sobell.com/CR2/index.html)

It looks like there are sample portions of the admin book as well via:

  http://www.admin.com/ (http://www.admin.com/)

May be I'll have the opportunity to browse physical copies at a bookstore before too long.

Thanks for the suggestions :)
Title: Re: Bourne / Bash Shell Scripting Resources
Post by: 40hz on July 07, 2011, 05:48 AM

May be I'll have the opportunity to browse physical copies at a bookstore before too long.


Very smart move doing that. Whenever possible I always try to eyeball a tech book before I plunk down cash. One thing I've learned - you can't always trust Amazon's reviews. Or go by what your friends think either!  ;D :Thmbsup:



Title: Re: Bourne / Bash Shell Scripting Resources
Post by: ewemoa on July 09, 2011, 01:03 AM
One thing I've learned - you can't always trust Amazon's reviews.
It's certainly challenging to decode whatever signal might be there sometimes :)

I appreciate their "Look Inside" feature when it's available -- in the current situation, that appears to be "yes" for the admin book and "no" for Sobell's book.
Title: Re: Bourne / Bash Shell Scripting Resources
Post by: 40hz on July 09, 2011, 09:33 AM
^There ya go then! ;D

That's why it pays to check for yourself. One person's "book o' wisdom" is another person's doorstop.
 :Thmbsup:

Title: Re: Bourne / Bash Shell Scripting Resources
Post by: ewemoa on July 09, 2011, 05:08 PM
I appreciate their "Look Inside" feature when it's available -- in the current situation, that appears to be "yes" for the admin book and "no" for Sobell's book.
Sorry if I was unclear above  :-[

What I meant was that it looks possible to use "Look Inside" for one book and not the other.

Haven't decided about the books yet...although both books seem to cover far more than shell scripting :)
Title: Re: Bourne / Bash Shell Scripting Resources
Post by: MilesAhead on July 09, 2011, 06:03 PM
I'm pretty sure I had an earlier edition of this book:
http://www.amazon.com/Unix-Nutshell-Fourth-Arnold-Robbins/dp/0596100299

The one I had was pocket size with a blue cover.  But the chapters in this are familiar.  Covers sh, bash and korn shells.  There should be a lot of useful examples if you are running a unix type OS.
Title: Re: Bourne / Bash Shell Scripting Resources
Post by: ewemoa on July 09, 2011, 07:46 PM
Thanks for the suggestion :)

It looks like it is "Look Inside"-compatible too.

Checking out the Amazon page I see it supposedly covers:


May be a fair bit more than what I'm interested in at this point, but it looks like I have another candidate for book browsing  ;)

I suppose it's worth checking out other O'Reilly titles -- there appear to be at least two:


Brief Table of Contents

Learning the bash Shell, Third Edition (O'Reilly Page which includes Full Table of Contents (http://oreilly.com/catalog/9780596009656)) 2005


bash Cookbook (O'Reilly Page which includes Full Table of Contents (http://oreilly.com/catalog/9780596526788)) 2007

Title: Re: Bourne / Bash Shell Scripting Resources
Post by: MilesAhead on July 09, 2011, 08:08 PM
The O'Reilly "Cookbook" series are usually a safe bet.  Depends what your main interest is. If it's more sysadmin or programmer oriented.
Title: Re: Bourne / Bash Shell Scripting Resources
Post by: Edvard on July 09, 2011, 11:41 PM
The "Bash by Example" articles are excellent!
Never seen them before, thanks!
As for part 3, I think it's less about Gentoo than it is an example of how to code an entire application in bash script.
I'll have to pack those into a PDF and make a printout...

BTW - many of the online resources I cited are available as PDF, and so should be printable at home or by any freindly neighborhood printing service.
Lulu.com also has many of them available has hard and soft covers, but they're not exactly cheap.
Title: Re: Bourne / Bash Shell Scripting Resources
Post by: MilesAhead on July 10, 2011, 01:51 AM
BTW - many of the online resources I cited are available as PDF, and so should be printable at home or by any freindly neighborhood printing service.
Lulu.com also has many of them available has hard and soft covers, but they're not exactly cheap.

I still have some binders kicking around. Ironically one has a copy of bind that I downloaded in Postscript format and printed on my HP Deskjet 500.  Used some ink but cheaper than buying the book, even in paperback. :)
Title: Re: Bourne / Bash Shell Scripting Resources
Post by: ewemoa on July 10, 2011, 02:36 AM
As for part 3, I think it's less about Gentoo than it is an example of how to code an entire application in bash script.
I suppose so.  I guess one might be helped slightly in understanding the article assuming some prior experience with Gentoo, but perhaps not a whole lot.

BTW - many of the online resources I cited are available as PDF, and so should be printable at home or by any freindly neighborhood printing service.
Lulu.com also has many of them available has hard and soft covers, but they're not exactly cheap.
-Edvard
Thanks for the tip!
Title: Re: Bourne / Bash Shell Scripting Resources
Post by: ewemoa on July 10, 2011, 02:48 AM
It appears there is a home page for the "bash Cookbook" (by the authors? Not the O'Reilly page):

  http://bashcookbook.com/ (http://bashcookbook.com/)

I noticed a link there to:

  Bash Guide for Beginners (http://tldp.org/LDP/Bash-Beginners-Guide/html/index.html)

From the "Why this guide?" section:

The primary reason for writing this document is that a lot of readers feel the existing HOWTO to be too short and incomplete, while the Bash Scripting guide is too much of a reference work. There is nothing in between these two extremes. I also wrote this guide on the general principal that not enough free basic courses are available, though they should be.

This is a practical guide which, while not always being too serious, tries to give real-life instead of theoretical examples. I partly wrote it because I don't get excited with stripped down and over-simplified examples written by people who know what they are talking about, showing some really cool Bash feature so much out of its context that you cannot ever use it in practical circumstances. You can read that sort of stuff after finishing this book, which contains exercises and examples that will help you survive in the real world.

From my experience as UNIX/Linux user, system administrator and trainer, I know that people can have years of daily interaction with their systems, without having the slightest knowledge of task automation. Thus they often think that UNIX is not userfriendly, and even worse, they get the impression that it is slow and old-fashioned. This problem is another one that can be remedied by this guide.

There appears to be a more recent version (http://tille.garrels.be/training/bash/).

Perhaps also of interest was:

  The Comprehensive List of bash Reference Documentation and Examples (http://www.bashcookbook.com/bashinfo/)

which also has a "bash Software Repositories and other Resources" list.

However...
As I've been looking into this topic, I find myself more attracted to learning about dash or the Bourne shell.  ;)

Title: Re: Bourne / Bash Shell Scripting Resources
Post by: Edvard on July 10, 2011, 03:38 AM
Looking around the site, came across:

  The Comprehensive List of bash Reference Documentation and Examples (http://www.bashcookbook.com/bashinfo/)

which also has a "bash Software Repositories and other Resources" list.
:o
Awesome find!!  :-*
As I've been looking into this topic, I find myself more attracted to learning about dash or the Bourne shell. ;)
Well, to each his own, I guess...  :P
Title: Re: Bourne / Bash Shell Scripting Resources
Post by: ewemoa on July 10, 2011, 03:39 AM
Well, to each his own, I guess...  :P
Well, at least at first, it seems dash / Bourne shell might be smaller targets :)
Title: Re: Bourne / Bash Shell Scripting Resources
Post by: ewemoa on July 10, 2011, 04:16 AM
I used to have a $9 "in a nutshell" book with many example sh scripts.. but I can't seem to find it to get the exact title.
Don't know if it was UNIX in a Nutshell (http://www.amazon.com/Unix-Nutshell-Fourth-Arnold-Robbins/dp/0596100299), but the author of that seems to have co-written a separate book on shell scripting:

  Classic Shell Scripting (http://www.amazon.com/Classic-Shell-Scripting-Arnold-Robbins/dp/0596005954)

Both appear to be "Look Inside" compatible :)

Brief Table of Contents

UNIX in a Nutshell, Fourth Edition (O'Reilly Page which includes Full Table of Contents (http://oreilly.com/catalog/9780596100292)) 2005

Chapter 1 Introduction
Chapter 2 Unix Commands
Chapter 3 The Unix Shell: An Overview
Chapter 4 The Bash and Korn Shells
Chapter 5 tcsh: An Extended C Shell
Chapter 6 Package Management
Chapter 7 Pattern Matching
Chapter 8 The Emacs Editor
Chapter 9 The vi, ex, and vim Editors
Chapter 10 The sed Editor
Chapter 11 The awk Programming Language
Chapter 12 Source Code Management: An Overview
Chapter 13 The Revision Control System
Chapter 14 The Concurrent Versions System
Chapter 15 The Subversion Version Control System
Chapter 16 The GNU make Utility
Chapter 17 The GDB Debugger
Chapter 18 Writing Manual Pages
Appendix A ISO 8859-1 (Latin-1) Character Set
Appendix B Bibliography

Classic Shell Scripting (O'Reilly Page which includes Full Table of Contents (http://oreilly.com/catalog/9780596005955)) 2005

Chapter 1 Background
Chapter 2 Getting Started
Chapter 3 Searching and Substitutions
Chapter 4 Text Processing Tools
Chapter 5 Pipelines Can Do Amazing Things
Chapter 6 Variables, Making Decisions, and Repeating Actions
Chapter 7 Input and Output, Files, and Command Evaluation
Chapter 8 Production Scripts
Chapter 9 Enough awk to Be Dangerous
Chapter 10 Working with Files
Chapter 11 Extended Example: Merging User Databases
Chapter 12 Spellchecking
Chapter 13 Processes
Chapter 14 Shell Portability Issues and Extensions
Chapter 15 Secure Shell Scripts: Getting Started
Chapter 16 Bibliography
Title: Re: Bourne / Bash Shell Scripting Resources
Post by: ewemoa on July 10, 2011, 04:31 AM
As a side note, I noticed that O'Reilly provides a "Browse Contents" feature for (some of?) its books and books.google.com sometimes has something akin to Amazon's "Look Inside".  May be there are other options for browsing book content...

Hmm...perhaps "Browse Contents" is just re-using Google content...

[ You are not allowed to view attachments ]
Title: Re: Bourne / Bash Shell Scripting Resources
Post by: ewemoa on July 10, 2011, 09:06 AM
Came across:

  BASH Debugger (http://bashdb.sourceforge.net/)

The Bash Debugger Project is a source-code debugger for bash that follows the gdb command syntax.

[ You are not allowed to view attachments ]

Apart from the obvious application, it seems like this might be handy for learning.
Title: Re: Bourne / Bash Shell Scripting Resources
Post by: ewemoa on July 14, 2011, 04:04 AM
Found this collection of tutorials:

  http://www.shelldorado.com/links/index.html#tutorials (http://www.shelldorado.com/links/index.html#tutorials)

The rest of the site is interesting too:

  http://www.shelldorado.com/ (http://www.shelldorado.com/)

Currently going through the Good Coding Practices (http://www.shelldorado.com/goodcoding/) section.
Title: Re: Bourne / Bash Shell Scripting Resources
Post by: Edvard on July 15, 2011, 01:05 AM
Ooh, I had forgotten about that site... Thanks!
My other favorite scripting resource is the most excellent Rob Van der Woude (http://www.robvanderwoude.com/) pages, even though there's no Bash love there :(

Still, thanks for reminding me about Shelldorado!
Title: Re: Bourne / Bash Shell Scripting Resources
Post by: ewemoa on July 15, 2011, 09:47 PM
My other favorite scripting resource is the most excellent Rob Van der Woude (http://www.robvanderwoude.com/) pages
Thanks for this link.  About to take a look :)

Don't know if you've seen this already, but the following from Shelldorado was new to me:

By the way, did you know that the command line

    $ ls -bart -simpson -is -cool

is a valid usage for the SOLARIS ls command?
Title: Re: Bourne / Bash Shell Scripting Resources
Post by: Edvard on July 16, 2011, 02:15 AM
 ;D

It's actually functionally equivalent to "ls -bartsimponcl" because all those letters are simply arguments that can be passed to the ls command and splitting the arg line and repeating letters doesn't affect the operation.

Still; quite amusing.