4 # Name : fred_techniques
5 # Author : Chris Koeritz
6 # Rights : Copyright (C) 2010-$now by Author
8 # Copyright (c) 2010-$now By Author. This script is free software; you can
9 # redistribute it and/or modify it under the terms of the simplified BSD
10 # license. See: http://www.opensource.org/licenses/bsd-license.php
11 # Please send updates for this code to: fred@gruntose.com -- Thanks, fred.
14 # this script is a collection of helpful bash practices that unfortunately
15 # sometimes slip my mind when i need them. it's intended to collect all the
16 # good bits so they don't slip away. feel free to re-use them in your own
21 # clean for loops in bash:
23 for ((i=0; i < 5; i++)) do
29 # removing an array element
30 # --> only works on arrays that have no elements containing a space character.
32 # define a 5 element array.
35 # remove element 2 (the 'c').
38 # set the array to slices of itself.
39 arr=(${arr[*]:0:$removepoint} ${arr[*]:(($removepoint+1))} )
41 # show the new contents.
47 # store to a variable name by derefercing it.
49 # shows how you can store into a variable when you are given only its name.
50 function store_to_named_var()
52 local name="$1"; shift
53 eval ${name}=\(gorbachev "perestroikanator 12000" chernenko\)
56 declare -a ted=(petunia "butter cup" smorgasbord)
58 store_to_named_var ted
59 echo ted is now ${ted[@]}