I am new using unix and I recently tried to create a code that would take some arguments and pass it to a python script and later use those arguments for downstream processes.
I am trying to use getopts but after I tried running the script it looks like my arguments were not stored in variables and anything downstream failed.
This is a piece of what I tried so far
#!/bin/bash
function usage() {
cat <<USAGE
Usage: $0 [-f fasta] [-o output name] [-m memory] [-t time] [-n number of tasks] [-c cores] [-g gpus] [-e extra]
Options:
-f fasta file
-o output name
-m memory to request
-t time to request
-n number of tasks
-c cores to request
-g gpus to request - no more than 4!
-e extra arguments for program
USAGE
}
while getopts ":f:o:m:t:n:c:g:e:h" flag
do
case "${flag}" in
f)
fasta=${OPTARG}
;;
o)
out_name=${OPTARG}
;;
m)
memory=${OPTARG}
;;
t)
time=${OPTARG}
;;
n)
number=${OPTARG}
;;
c)
cores=${OPTARG}
;;
g)
gpus=${OPTARG}
;;
e)
extra=${OPTARG}
;;
h)
usage
;;
:)
echo "Invalid option: $OPTARG" 1>&2
usage
exit 1
;;
\?)
echo "Invalid option"
usage
exit 1
;;
esac
done
python3 /scratch/amolinav/programs/my_script_single.py ${fasta} ${out_name} ${memory} ${time} ${number} ${cores} ${gpus} ${extra}
I would really appreciate if someone could point out where I am making the mistake. Thank you so much in advance for your help