I have a program that we will call A, and two other programs that we will call B and C. Program A is a BASH script that simply can runs the other two, and displays help options. B and C are BASH programs that execute other programs in the C language. The basic code of program A is:
while getopts "hv" option; do
case ${option} in
h) # Call the Help function
Help
exit;;
v) # Call the Version function
Version
exit;;
\?) # Invalid option
echo "Invalid option. Use flag -h for help."
exit;;
esac
done
if [ "$1" = "B" ] ; then
source <path_to>/B.sh
fi
if [ "$1" = "C" ] ; then
source <path_to>/C.sh
fi
My question is if it is possible to use getopts for specific options when executing B and for other specific options when executing C, in both cases when using A as the main program. For example, if -t is the number of threads we want the programs called by script B to run with:
A B -t 10
The getopts of program B is something like this:
while getopts t:d: flag
do
case "${flag}" in
t) NCPUS=${OPTARG};; # Number of CPUs using by the software executed
d) DATA_PATH=${OPTARG};; # data path
esac
done
I remember that there is some bioinformatics program that does this in BASH... maybe I could see how it does it in the code, but I don't remember the name. Any suggestion?
Bioinformatics program? Pipeline? Maybe you're thinking of Nextflow. You can use Nextflow to manage your pipeline and the bash part can just be copy-pasted to the script block inside a process (a task definition in Nextflow lingo).