I have a bash script that uses getopts
to parse command line arguments. One of the arguments, -l <name>
is directed to an if
statement that determines certain settings. Is it possible to have autocomplete work in the command line for entering the <name>
parameter?
Here is the command line parsing part (getopts
) of my script:
while getopts 'l:r:m:?h' c
do
case $c in
l)
library=$OPTARG
;;
r)
rename_config=$OPTARG
;;
m)
align_mm=$OPTARG
;;
h|?) usage
;;
esac
done
The library option (-l
) refers to this part of the script:
if [ $library = "bassik" ];
then
read_mod="clip"
clip_seq="GTTTAAGAGCTAAGCTGGAAACAGCATAGCAA"
echo "Bassik library selected"
elif [ $library = "moffat_tko1" ];
then
read_mod="trim"
sg_length=20
echo "Moffat TKO1 library selected"
elif [ $library = "sabatini" ];
then
read_mod="trim"
sg_length=20
echo "Sabatini library selected"
fi
The part where the auto-completion should work are for "bassik", "moffat_tko1", and "sabatini" parameters.
So far, I have tried just hitting <TAB>
right after ./script.sh -l
, but that does not work. I have googled it, but could not find anything that fits my situation (not sure also how to call this, new to bash).