Re: Some bash question

On Saturday, 06 augustus, 2011 bij 15:06:04u +0200, Houghi schreef:

By re-writing my scripts I cam across something I use a lot:

FOO ()
echo "BAR"

Two questions:

1) How is this called?

The function FOO is called by the use of FOO in the main program or other function.

2) The () could contain something

No, it is forbidden by the law of Bourne to contain anything ;)

How and where is this explained?

Should be in the manual page for sh or bash. Or look at a well written book
on shell programming.

Incidentally, you should collect all your commonly used functions into a library file
and then source that from the individual scripts.

eg something like


if [ -r "${script_functions}" ]
. "${script_functions}"
/bin/echo -e "\007%ERROR - script functions file cannot be read!" >&2
exit 1

Thus when you need to add some bug fix or enhancement to a function, you only have
to change it in one file and not tens of files.

And my personal opinion is that for true portability, best to keep scripts as
Bourne shell compliant and not use bashisms.

What you do on your machine is your affair, but you appear to be asking for some
advice, and other readers hopefully are also interested.