topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Tuesday March 19, 2024, 4:31 am
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Last post Author Topic: Bourne / Bash Shell Scripting Resources  (Read 14952 times)

ewemoa

  • Honorary Member
  • Joined in 2008
  • **
  • Posts: 2,922
    • View Profile
    • Donate to Member
Bourne / Bash Shell Scripting Resources
« on: July 04, 2011, 10:20 PM »
Started to work through:

  Steve's Bourne / Bash shell scripting tutorial

steve-parker-site-image.jpg

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?
« Last Edit: July 04, 2011, 10:23 PM by ewemoa »

MilesAhead

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 7,736
    • View Profile
    • Donate to Member
Re: Bourne / Bash Shell Scripting Resources
« Reply #1 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.. :)

« Last Edit: July 04, 2011, 11:43 PM by MilesAhead »

Edvard

  • Coding Snacks Author
  • Charter Honorary Member
  • Joined in 2005
  • ***
  • Posts: 3,017
    • View Profile
    • Donate to Member
Re: Bourne / Bash Shell Scripting Resources
« Reply #2 on: July 06, 2011, 05:44 AM »
« Last Edit: July 06, 2011, 05:55 AM by Edvard »

ewemoa

  • Honorary Member
  • Joined in 2008
  • **
  • Posts: 2,922
    • View Profile
    • Donate to Member
Re: Bourne / Bash Shell Scripting Resources
« Reply #3 on: July 06, 2011, 07:45 PM »
Thanks for the comments and suggestions  :Thmbsup:

The Learn About Bash Scripting section of the suggested Getting Started with BASH 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
  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
  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
  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...
« Last Edit: July 06, 2011, 08:36 PM by ewemoa »

MilesAhead

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 7,736
    • View Profile
    • Donate to Member
Re: Bourne / Bash Shell Scripting Resources
« Reply #4 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.

40hz

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 11,857
    • View Profile
    • Donate to Member
Re: Bourne / Bash Shell Scripting Resources
« Reply #5 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.


NixBook.jpg


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) (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:


ewemoa

  • Honorary Member
  • Joined in 2008
  • **
  • Posts: 2,922
    • View Profile
    • Donate to Member
Re: Bourne / Bash Shell Scripting Resources
« Reply #6 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:

ewemoa

  • Honorary Member
  • Joined in 2008
  • **
  • Posts: 2,922
    • View Profile
    • Donate to Member
Re: Bourne / Bash Shell Scripting Resources
« Reply #7 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.
I see that bits of this book are available for preview via:

  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/

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

Thanks for the suggestions :)

40hz

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 11,857
    • View Profile
    • Donate to Member
Re: Bourne / Bash Shell Scripting Resources
« Reply #8 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:




ewemoa

  • Honorary Member
  • Joined in 2008
  • **
  • Posts: 2,922
    • View Profile
    • Donate to Member
Re: Bourne / Bash Shell Scripting Resources
« Reply #9 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.
« Last Edit: July 09, 2011, 01:06 AM by ewemoa »

40hz

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 11,857
    • View Profile
    • Donate to Member
Re: Bourne / Bash Shell Scripting Resources
« Reply #10 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:


ewemoa

  • Honorary Member
  • Joined in 2008
  • **
  • Posts: 2,922
    • View Profile
    • Donate to Member
Re: Bourne / Bash Shell Scripting Resources
« Reply #11 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 :)

MilesAhead

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 7,736
    • View Profile
    • Donate to Member
Re: Bourne / Bash Shell Scripting Resources
« Reply #12 on: July 09, 2011, 06:03 PM »
I'm pretty sure I had an earlier edition of this book:
http://www.amazon.co...obbins/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.

ewemoa

  • Honorary Member
  • Joined in 2008
  • **
  • Posts: 2,922
    • View Profile
    • Donate to Member
Re: Bourne / Bash Shell Scripting Resources
« Reply #13 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:

  • Solaris 10, the latest version of the SVR4-based operating system, GNU/Linux, and Mac OS X
  • Bash shell (along with the 1988 and 1993 versions of ksh)
  • tsch shell (instead of the original Berkeley csh)
  • Package management programs, used for program installation on popular GNU/Linux systems, Solaris and Mac OS X
  • GNU Emacs Version 21
  • Introduction to source code management systems
  • Concurrent versions system
  • Subversion version control system
  • GDB debugger

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) 2005

  • Chapter 1 bash Basics
  • Chapter 2 Command-Line Editing
  • Chapter 3 Customizing Your Environment
  • Chapter 4 Basic Shell Programming
  • Chapter 5 Flow Control
  • Chapter 6 Command-Line Options and Typed Variables
  • Chapter 7 Input/Output and Command-Line Processing
  • Chapter 8 Process Handling
  • Chapter 9 Debugging Shell Programs
  • Chapter 10 bash Administration
  • Chapter 11 Shell Scripting
  • Chapter 12 bash for Your System
  • Appendix A Related Shells
  • Appendix B Reference Lists
  • Appendix C Loadable Built-Ins
  • Appendix D Programmable Completion

bash Cookbook (O'Reilly Page which includes Full Table of Contents) 2007

  • Chapter 1 Beginning bash
  • Chapter 2 Standard Output
  • Chapter 3 Standard Input
  • Chapter 4 Executing Commands
  • Chapter 5 Basic Scripting: Shell Variables
  • Chapter 6 Shell Logic and Arithmetic
  • Chapter 7 Intermediate Shell Tools I
  • Chapter 8 Intermediate Shell Tools II
  • Chapter 9 Finding Files: find, locate, slocate
  • Chapter 10 Additional Features for Scripting
  • Chapter 11 Working with Dates and Times
  • Chapter 12 End-User Tasks As Shell Scripts
  • Chapter 13 Parsing and Similar Tasks
  • Chapter 14 Writing Secure Shell Scripts
  • Chapter 15 Advanced Scripting
  • Chapter 16 Configuring and Customizing bash
  • Chapter 17 Housekeeping and Administrative Tasks
  • Chapter 18 Working Faster by Typing Less
  • Chapter 19 Tips and Traps: Common Goofs for Novices
  • Appendix A Reference Lists
  • Appendix B Examples Included with bash
  • Appendix C Command-Line Processing
  • Appendix D Revision Control
  • Appendix E Building bash from Source
« Last Edit: July 10, 2011, 04:17 AM by ewemoa, Reason: Updated with Table of Contents and related info, edited title of \"bash Cookbook\", added pub years »

MilesAhead

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 7,736
    • View Profile
    • Donate to Member
Re: Bourne / Bash Shell Scripting Resources
« Reply #14 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.

Edvard

  • Coding Snacks Author
  • Charter Honorary Member
  • Joined in 2005
  • ***
  • Posts: 3,017
    • View Profile
    • Donate to Member
Re: Bourne / Bash Shell Scripting Resources
« Reply #15 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.

MilesAhead

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 7,736
    • View Profile
    • Donate to Member
Re: Bourne / Bash Shell Scripting Resources
« Reply #16 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. :)

ewemoa

  • Honorary Member
  • Joined in 2008
  • **
  • Posts: 2,922
    • View Profile
    • Donate to Member
Re: Bourne / Bash Shell Scripting Resources
« Reply #17 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!

ewemoa

  • Honorary Member
  • Joined in 2008
  • **
  • Posts: 2,922
    • View Profile
    • Donate to Member
Re: Bourne / Bash Shell Scripting Resources
« Reply #18 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/

I noticed a link there to:

  Bash Guide for Beginners

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.

Perhaps also of interest was:

  The Comprehensive List of bash Reference Documentation and Examples

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.  ;)

« Last Edit: July 10, 2011, 03:38 AM by ewemoa »

Edvard

  • Coding Snacks Author
  • Charter Honorary Member
  • Joined in 2005
  • ***
  • Posts: 3,017
    • View Profile
    • Donate to Member
Re: Bourne / Bash Shell Scripting Resources
« Reply #19 on: July 10, 2011, 03:38 AM »
Looking around the site, came across:

  The Comprehensive List of bash Reference Documentation and Examples

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

ewemoa

  • Honorary Member
  • Joined in 2008
  • **
  • Posts: 2,922
    • View Profile
    • Donate to Member
Re: Bourne / Bash Shell Scripting Resources
« Reply #20 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 :)

ewemoa

  • Honorary Member
  • Joined in 2008
  • **
  • Posts: 2,922
    • View Profile
    • Donate to Member
Re: Bourne / Bash Shell Scripting Resources
« Reply #21 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, but the author of that seems to have co-written a separate book on shell scripting:

  Classic Shell Scripting

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) 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) 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

ewemoa

  • Honorary Member
  • Joined in 2008
  • **
  • Posts: 2,922
    • View Profile
    • Donate to Member
Re: Bourne / Bash Shell Scripting Resources
« Reply #22 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...

oreilly-browse-contents.pngBourne / Bash Shell Scripting Resources

ewemoa

  • Honorary Member
  • Joined in 2008
  • **
  • Posts: 2,922
    • View Profile
    • Donate to Member
Re: Bourne / Bash Shell Scripting Resources
« Reply #23 on: July 10, 2011, 09:06 AM »
Came across:

  BASH Debugger

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

bashdb-where.pngBourne / Bash Shell Scripting Resources

Apart from the obvious application, it seems like this might be handy for learning.

ewemoa

  • Honorary Member
  • Joined in 2008
  • **
  • Posts: 2,922
    • View Profile
    • Donate to Member
Re: Bourne / Bash Shell Scripting Resources
« Reply #24 on: July 14, 2011, 04:04 AM »
Found this collection of tutorials:

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

The rest of the site is interesting too:

  http://www.shelldorado.com/

Currently going through the Good Coding Practices section.