I want to have a script both define functions and have the ability to run an external program calling one of them. This is the simplified construct:
#!/bin/bash
foo() {
echo "this is foo"
}
bar() {
echo "this is bar"
}
case "$1" in
one)
foo
;;
two)
export bar
/usr/bin/watch bar
;;
*)
echo $0 "{one|two}"
exit 0
;;
esac
So if I invoke /path/to/script one the foo function runs and it exits as expected. I want to ability to run the bar function as if it were a stand-alone program via `/usr/bin/watch bar` but this doesn't work as expected.
$ /path/to/script two
Every 2.0s: bar Mon Jul 30 02:16:25 2012
sh: bar: command not found
How can I accomplish it?
---------- Post updated at 03:18 AM ---------- Previous update was at 02:16 AM ----------
Solved...
export -f bar