
Advanced Bash Scripting - mbowcock
http://www.tldp.org/LDP/abs/html/
======
Adaptive
This is hands down the best Bash resource online or in print. Don't let the
"advanced" throw you off. It's the source of pretty much everything (of
significance) that I know about bash.

For other applications it makes sense to use your scripting language of choice
(libraries, etc.) but in any situation where you need absolute portability or
availability on an otherwise bare system, bash is the way to go.

There are whole projects like the Arch Linux Installation Framework (AIF)
written in bash for this reason.

Named arrays, quick string handling and the [[ ]] test syntax alone make this
worth reading, and that's just scratching the surface.

~~~
derleth
> in any situation where you need absolute portability or availability on an
> otherwise bare system, bash is the way to go.

Interestingly, this is why Debian uses dash: A smaller shell is more portable.

~~~
tingletech
How is that portable, across different architectures?

I have to work in Solaris, SUSE SLES, some other linux where I don't know what
they run, and OS X and I don't have root on most of those. bash seems to work
the same everywhere and always seems to be there when I get access to a newly
provisioned environment.

~~~
thristian
Not every Unix-like OS comes with bash, and certainly not by default. In
particular, Solaris ships with a particularly crippled /bin/sh, although they
do have a proper POSIX-compatible Bourne shell at /usr/xpg4/bin/sh.

If your Solaris machines have /bin/bash available, consider yourself very
lucky.

------
eliben
While bash is certainly more pleasant to write and use than the other shell
languages, I made myself a rule I abide by, a long time ago. Never use shell
to write anything non-trivial. Unless it's a one liner that just stitches some
Unix commands together, just use a real language (Python, for example). I
can't count how many times I found myself being grateful for this decision.
Shell scripts just have a way of growing in size and complexity, and
swallowing the shell pill is the quick road into abyss.

~~~
vlisivka
I wrote large bunch of software in shell, so I have habit to use strict mode
("set -ue"), so shell scripts are much safer.

I write scripts like large programs from scratch: decomposition, error
handling, proper logging, unit testing, packaging, etc.

I wrote my own library with few useful modules, which is designed for strict
mode (bash-modules on assembla), which I recommend to use even for trivial
programs.

I have no problems with bash.

~~~
sanderjd
Why did you do all those things? Did you _have_ to use bash for all that
software? Were you concerned about portability? Do you just dislike python?

I have no trouble understanding how complex programs _can_ be written in bash,
but I have never understood _why_.

~~~
vlisivka
Because I can. Sometimes - yes, sometimes - no, but why not? No, I am fine
with Linux. Yes, I dislike python.

I hope, it is temporary problem. ;-)

------
jhaglund
I recently found this site useful. I wrote a script that glued together some
commands to be run by cron. Then the requirements grew and the script's
complexity grew, and grew, and before long I learned that bash scripts support
functions.

At this point, I wished I had started in python.

To answer maven911, I usually do LAMP stack development but pick up all kinds
of technologies along the way.

~~~
Maven911
Thanks for answering, I should have given some background on why I am asking
this, bash is one of many technologies that I need to learn for the job - our
product unfortunately uses thousands of lines of bash scripting, and I have
never gotten around finishing this guide - mostly due to laziness (after work)
since I don't have time during the job to look into it as we are always in
fire-fighting mode.

------
1010011010
Here's the short version of the Advanced Bash Scripting Guide: "Use Python".

Long bash scripts are less readable and maintainable than python scripts.

~~~
tikhonj
It doesn't have to be Python--you can use pretty much any language you want,
so just use your favorite one be it Ruby or Python or Haskell or whatever.

I personally only use Bash when the script is just a trivial translation of
commands I enter.

~~~
Maven911
sometimes you have no choice, such as working on telecom systems which have a
stripped down Linux version running on it and there is no python/perl
interpreter available.

~~~
tikhonj
That's certainly a possibility. For me, however, the vast majority of scripts
I write will only ever run on my own computer or maybe also on some AWS
instances. I suspect this varies a lot based on what sorts of things you
generally work on.

------
kaichanvong
I'd really like this as an Epub, Pdf or something I can just stick on my iPad.
Anyone know of a link for this... or am I going to have to do this for
everyone? :]

~~~
anoother
Please share if you do! epub would be perfect

------
Maven911
has anyone gone through the entire book/guide, and i wonder is it because of
your job and what other technologies you have to know in-depth

~~~
tingletech
I use it more as a reference / scan it for inspiration when I'm stuck. Way
better than the bash man page...

I use it like I use 'perldoc perl' or <http://docs.python.org/> or
<https://docs.djangoproject.com/en/1.3/> or
<https://developer.mozilla.org/en/JavaScript/Guide> or
<http://docs.jquery.com/Main_Page> or
<http://www.dpawson.co.uk/xsl/sect2/sect21.html> etc.

------
przemoc
ABS can be handy for some quick look up, but if you want to learn Bash then go
with Greg's Bash Guide:

<http://mywiki.wooledge.org/BashGuide>

Check also the list of Bash online tutorials:

<http://wiki.bash-hackers.org/scripting/tutoriallist>

~~~
mbubb
Thanks for the link to Gregg's BASH guide. Useful information.

------
taf2
hasn't this resource been around the block for 10+ years? I remember googling'
"advanced bash scripting" function in college and finding a resource just like
this one...

