[ale] Bash-fu question

Richard Bronosky Richard at Bronosky.com
Fri Oct 23 19:55:00 EDT 2009


On Fri, Oct 23, 2009 at 7:25 PM, Michael Hirsch <mdhirsch at gmail.com> wrote:
> for ii in vcalendar pdf_viewer; do
>    cd $ii
>    ./autogen.sh && make && sudo make install
>    cd ..
> done

Michael, great catch on the "cd .." bit! I would add a little bit more to that:

#!/bin/bash
## Exit on use of an uninitialized variable
set -o nounset
## Exit if any statement returns a non-true return value (non-zero).
set -o errexit
## This will allow you to run /path/to/script.sh from anywhere instead
of cd /path/to; ./script.sh
## (Important for cron scripts. Good habit to get into.)
cd $(dirname $0)

DIRS=(
    vcalendar
    pdf_viewer
    other_plugin_I_want
)

for DIR in "${DIRS[@]}"; do
    cd $DIR
    ./autogen.sh && make && sudo make install
    cd ..
done

The benefits of using a bash array include having the option to put
each entry its own line, easily comment out entries, your entries can
have spaces in them. This is all demonstrated by:
a=(
    qwer
    # You can vary indention for readability.
        asdf
    "zxcv zcxv"
)
for v in "${a[@]}"; do echo "XX-${v}-XX"; done;

If you don't believe that it is space-safe, change the "echo" command
to "touch".

May the bash-fu be with you.

-- 
.!# RichardBronosky #!.



More information about the Ale mailing list