help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Help-bash] [newbie] fail on missing command/function?


From: Tom Roche
Subject: [Help-bash] [newbie] fail on missing command/function?
Date: Fri, 01 Jun 2012 18:37:12 -0400
User-agent: GNU Emacs 24.1.50.1 (x86_64-pc-linux-gnu, GTK+ Version 2.20.1)

summary: How to make bash fail when one's script calls an undefined
command or function? Ways to do this in bash versions 3-4 are
appreciated; I must work on systems with both.

details:

While a relative newbie, I know enough (from coding other languages)
to modularize my code, i.e., to use bash functions. So my scripts tend
to be structured like

define constants/globals
define a function
define another function
...
dispatch list of functions

My "function dispatcher" is usually like

for CMD in \
  "setup" \
  "function1" \
...
  "function" \
  "teardown" \
 ; do
  echo -e "\n$ ${CMD}" 1>&2
  eval "${CMD}"
done

This has worked fairly well, in that I get usable traces on stdout and
stderr. But I'm definitely open to suggestions for improvement,
specifically regarding one problem: I like to fail-fast (especially
now that I'm using bash to drive big data-analysis jobs), and my
scripts keeps on chugging despite not finding a function (or command).
E.g.,

> $ setup
> ++./mergeWithEmissions.sh:125: setup: [[ ! -d 
> /home/me/ioapi-hack-R/data/emis/cooked ]]
> ++./mergeWithEmissions.sh:128: setup: set +xv

> $ getMSFFile

> $ getUnitConversionDatavar
> ./mergeWithEmissions.sh: line 488: getUnitConversionDatavar: command not found

> $ getWindowedEmissions
> ./mergeWithEmissions.sh: line 488: getWindowedEmissions: command not found

How can I *readably* dispatch functions (i.e., producing traces
similar to the the above), yet get fail-fast when "command not found"?
Ways to do this in bash versions 3-4 are appreciated: my data-analysis
jobs run on big linux clusters that often have rather downlevel app
versions: bash 3.x is quite common.

TIA, Tom Roche <address@hidden>



reply via email to

[Prev in Thread] Current Thread [Next in Thread]