Bash scripting web site

Michael Torrie torriem at gmail.com
Tue Sep 24 09:05:23 MDT 2013


On 09/24/2013 04:40 AM, Dan Egli wrote:
> Anyone know of a good site that can tell/remind me how to program in Bash
> shell scripts? I remember most of it, but lately I have been having a hard
> time remembering exactly how certain parts work. I'm especially looking for
> good tutorials/references on:
> 
> Bash array (i.e. ARR1={"a", "b", "c"} type of thing)
> 
> Pattern Matching (i.e. things like ${MYVAR##X1} or however it works)

Sometimes I just use sed for pattern matching.

> Also, I don't recall for sure if it's possible, but if so, this site should
> also indicate how to use default values in variables, something equivalent
> to this, but done without the multiple steps:
> 
> read P; [ -z $P ] P="No Assigned Value"
> 
> echo $P

Often I find it quickest just to do it brute force:
read P
if [ -z "$P" ]; then
	P="No assigned value"
fi

Always put your stuff in quotes, otherwise test will not see it if it's
a zero-length string

In general, Bash is a nifty tool, but often times I find that another
language like Python or Perl might be the more appropriate tool if I
find myself doing a lot of more advanced bash stuff.


More information about the PLUG mailing list