Quote:
Originally Posted by sneakyimp
I'm grateful for this. However, I've been reading bash-beginners-guide and it's not the smoothest introduction. It's kind of an awkward combination of vague and precise details.
|
Like grail, I think the selection you posted stands on its own well enough. Although I admit that if you have limited prior familiarity with the
Unix concepts of environment and process forking, the brief mention there may not stand out.
The shell is a special kind of environment in that it puts the many powerful Unix concepts and system services literally and interactively at your fingertips.
Quote:
"Although most users think of the shell as an interactive command interpreter, it is really a programming language in which each statement runs a command. Because it must satisfy both the interactive and programming aspects of command execution, it is a strange language, shaped as much by history as by design."
- Brian W. Kernighan and Rob Pike, The UNIX Programming Environment, 1984
|
So some familiarity with those Unix/Linux basics will go a long way toward understanding how the shell is intended to work (and such familiarity is listed as a prerequisite in the guide).
Quote:
Originally Posted by sneakyimp
That seems specific and yet totally uninformative at the same time.
|
That statement reminds me of a fortune, something about a helicopter pilot in Redmond... but I digress.
Try to not get bogged down, and if you can't figure something out, you know where to ask for help!
Quote:
Originally Posted by sneakyimp
The main problem I'm having is understanding the script syntax. E.g., when and why do we use quote marks and what's the point of all the double parens and square brackets and what's the role of the dollar sign, and why put a semicolon after the brackets in an if statement and how do the || and && operators effect control within the script, etc.
|
The syntax is different from many other languages, but still it is just another syntax.
To add to what grail has already said, and anticipate a few other questions...
The [ character is actually a command, the same as test, and not just a syntax element. To see this...
Code:
$ which [
/usr/bin/[
$ which test
/usr/bin/test
One consequence of this is that you must separate the enclosing brackets from the enclosed arguments with whitespace, just as you must separate the arguments of any other command from the command itself! (Actually bash uses a built-in version of [, but the behavior is the same).
Code:
[ $# -gt 1 ] - right!
[$# -gt 1] - error!
The double square-bracket test syntax, [[...]] is an extended test notation introduced by ksh but now adopted by bash as well. It differs from the original test in that word and wildcard expansions are not performed, so quoting is less important. It also adds a list of test conditions not availale with the older test syntax, but it supports all of the older options so that you can always use [[...]], whatever test condition you are using.
Shell scripting has a few quirks, but it is well worth gaining some proficiency with it. Once you have gained basic familiarity it will become one of the most used and most powerful tools in your bag of tricks!
Quote:
Originally Posted by sneakyimp
I may have to get the book. Kinda surprising that book is 560 pages!
|
I think it is a very good book. It is tutorial in style, but also makes a very good reference. It includes a little of the history of common shells, and their differences as well.
And unlike many computer books, it is not likely to become outdated any time soon! The shell is a well established and slowly changing component at the core of Unix/Linux, so the book will remain relevant for a long time - money well spent.
Good luck!