# Shell Scripting Books



## Phishfry (Dec 6, 2016)

I need to learn shell scripting before programming so I bought some used books.
Are these any good? Most from early 2000's but i doubt much has changed. 

Mastering Unix Shell Scripting

Beginning Shell Scripting

Beginning Portable Shell Scripting

Shell Scripting Recipes



I bought a C book too.
http://ineasysteps.com/products-page/all_books/c-programming-in-easy-steps-4th-edition-2/


----------



## wblock@ (Dec 7, 2016)

Shell _is_ programming.  It's just that the shell lacks so many basic tools that it's crude and difficult to do anything non-trivial.

I don't have any of those books, although some of the author names are familiar. I would lean toward the third one, but don't really know.  An alternative is just the sh(1) man page and all the system shell scripts.  Some are done well, some are sloppy and make assumptions, but they all serve as real examples.

C is not meant for everything, either, and is poorly-suited for many things.  Like strings, for example.


----------



## sko (Dec 7, 2016)

I really liked "classic shell scripting" [1] as it doesn't throw you right into one specific shell and forces you to build some example "application" purely with the shells abilities, but instead first introduces most classic tools and commands that are available on any unix system and which are usually glued together by shell scripts. All examples are pure sh, with notes about other shells when useful, but not focused on bash as with a lot of newer books. So everything you learn about scripting in this book is universally applicable to nearly any UNIX-derived system (except some minor variations of some tools like sed). An extra chapter talks specifically about portability of shell scripts.

It also offers a nice quick introduction to regex and a whole chapter on awk, which are really handy for processing text based data. Most scripts I wrote to automate ZFS-related tasks use awk to process output of zpool or zfs commands.

Another thing I like about this book: it doesn't force you to read from the beginning to the end like some newer books (The "head first" books are especially terrible IMHO). So if you need a quickstart only on one specific topic, just go to that chapter and start reading without having to worry about huge code examples that had been started and modified from chapter 1 throughout the whole book.

So if you're starting from the basics, this book gives you a very broad introduction and quite a good toolset to start with. Shell scripting itself isn't that complicated or extensive - it's mostly about how well you know the available tools and how to use them effectively within your scripts, and IMHO this mindset is covered really well in this book.



[1] http://shop.oreilly.com/product/9780596005955.do


----------



## Phishfry (Dec 7, 2016)

I saw Classic Shell Scripting for $12 and the rest only cost me $4. I will pick up your suggestion. There were 3 at the $12-$15 range that sounded relevant.
The other two:

Shell Scripting Tutorial by Steve Parker

Expert Shell Scripting by Ron Peters

What about curses. Is similar enough to ncurses to get the book?

One problem with these books is they are geared to Linux and OSX.


----------



## Phishfry (Dec 7, 2016)

I am working tword ncurses programming. I did not know that I could use python or perl with ncurses. That makes it a good starting point or me. Plus I like the way the finished product looks. I had no idea that vim or mc were ncurses based until I started reading.

I found my lack of shell scripting with gpio work to be frustrating. I can get stuff done but with many more lines of text. When I realized that I did not know what `jot` was that was the clue that it was time for some books. I have no fundamentals. Just winging it having a good time.


----------



## Maxnix (Dec 7, 2016)

Phishfry said:


> One problem with these books is they are geared to Linux and OSX.


I would suggest you this tutorial: http://grymoire.com/Unix/Sh.html too. I think it's a good tutorial about pure Bourne Shell programming. Note that there are some differences that regard some edge cases between FreeBSD's /bin/sh and the one used by the author (Solaris), but Bruce Barnett points out them too.


----------



## Phishfry (Dec 7, 2016)

Once I realized that I could daemonize my shell script with rc.d it dawned on me how powerful it could be. Easily making usable services.

What would be closer to FreeBSD book-example wise. Solaris or OSX?


----------



## sko (Dec 7, 2016)

(Open)Solaris' Bourne shell - or better say the ones used by most illumos derivates - has some quirks, but is quite similar to the one in FreeBSD. Make sure to use the "newer" Bourne shell, not the legacy one some illumos-derivates keep at /bin/sh for backwards compatibility.

Apple - as always - doesn't care about any (de-facto) stardards and changes nearly evertything at will. So I wouldn't count on any literature on OSX to be compatible to anything found in most other UNIX-derived system.

Development for curses stopped sometime in the mid 90s when essentially everyone switched to ncurses, which was free of AT&T code. ncurses is still actively maintained and developed, so that's the library I'd go for.

If you are looking on how to expand beyond the capabilities of shell scripting, I'd highly recommend Perl. If you have a background in shell scripting, basic Perl feels just natural and is very easy to pick up. Even more if you know or planning on learning C, as Perl imported many concepts and notations from C. It's relatively easy to switch between shell- or Perl-scirpts and C during the day.
All the Alpaca- and Llama-Books are a great introduction - I've started with the Alpaca-/Llama-Series and later got the Camel-Book which is a really good day-to-day reference or refresher on any topic. For a really deep dive which is beneficial not only for Perl coding, I can highly recommend "Higher-Order Perl" [1], which introduces really interesting concepts like e.g. applying functional paradigms to Perl. I was playing around with Scala (+Cassandra and Spark) when I started reading this Book the first time, and apart from some concepts for distributed/multi-node computing, I realized what I secretly felt from the beginning with Scala: It just feels like a strange, mangled dialect of Perl with lots of restrictions and the need for a fat JVM that gulps tons of RAM for even very basic tasks...
If you ever find yourself enthusiastic about languages like Scala or it's targeted big-data frameworks, just have a look at Manta from joyent or watch the talk about it Bryan Cantrill gave; _Bringing the Unix Philosophy to Big Data_ [2]. I found this concept to be a real eye-opener on how powerful classic UNIX-tools (to which I'd count Perl as a glue-layer) still are, even on huge distributed systems, and learning to use them is much more valuable and practical than any fancy new domain-specific language for the currently coolest new framework out there.

BTW: For C I still like the original K&R for ANSI C the most - it's concise, clear and straight to the point yet still easy and somewhat entertaining to read. Within <200 pages you know everything there is to know about C. I've tried to read "Head First: C" once as a refresher after some years without coding much in C, but I got really frustrated with the slow and awkward pace of the book, so I just went through K&R again on one evening and was good to go...


[1] http://hop.perl.plover.com/
[2] https://www.youtube.com/watch?v=S0mviKhVmBI


----------



## jrm@ (Dec 7, 2016)

Here are some other useful shell scripting resources.

 http://mywiki.wooledge.org/BashFAQ (It's called *Bash*FAQ, but it's useful for POSIX sh as well).
 http://www.shellcheck.net/  or http://www.freshports.org/devel/hs-ShellCheck/ (I've heard complaints; I find it useful.)
 http://www.freshports.org/devel/checkbashisms/ (This is probably redundant if you use shellcheck.)
 http://explainshell.com (I haven't used it much, but it seems handy for a beginner.)


----------



## Oko (Dec 7, 2016)

Phishfry said:


> I need to learn shell scripting before programming so I bought some used books.
> Are these any good? Most from early 2000's but i doubt much has changed.
> 
> Mastering Unix Shell Scripting
> ...



No you didn't get a single good book! Look for my recent post about UNIX books as a replay for to somebody. You will find enough to get you started.


----------



## Phishfry (Dec 7, 2016)

OK I bought this for cheap from your post.
UNIX Shell Programming, Sams Revised 1989


----------



## sidetone (Dec 8, 2016)

I  have Sams Teach Yourself Shell Programming in 24 Hours 2nd Edition.

It focuses on Bourne shell, then it shows variants for Korn, Zsh and Bash. There are too many books on Bash, so I got this one that focused more on the original Bourne and on Korn.

It focuses on portability.


----------



## ANOKNUSA (Dec 8, 2016)

Maxnix said:


> I would suggest you this tutorial: http://grymoire.com/Unix/Sh.html too.



I've had this bookmarked for years. It's what I use for reference, since I only write a shell script once in a great while  Greg's Wiki can be a good source, to. It specifically teaches Bash, but clearly explains Unix interface concepts in the process. It also clearly outlines what makes Bash different from other Unix shells, and (as I recall) prefers Bourne-compatible syntax in its lessons when more than one choice is available, so once you've learned from that guide how to write Bash scripts you can refer to it to write good old Bourne syntax while avoiding Bashisms, or see what features other Bourne-/Almquist-family shells offer that Bash does not.


----------

