I am trying to understand a piece of bash script that uses getopts.
I have
#!/bin/bash
function Argparser () {
while getopts 'o:dfath' arg "$@"; do
case $arg in
'o')
echo "oooooh"
output_dir=${OPTARG}
;;
'd')
echo 'ddddddd'
use_data_calib=true
;;
?)
echo "UNKNWON ARGS: ${OPTARG} "
exit 1
;;
esac
done
}
#----------------------------------------
# user parameters
#----------------------------------------
# data directory(required)
data_root_dir=$1
# output directory
output_dir=${data_root_dir}/videos
declare others=${@:2}
Argparser ${others}
#declare use_data_calib=false #<<-----HERE
echo ${output_dir}
echo ${data_root_dir}
echo ${others}
echo ${use_data_calib}
First I would like to understand what dfath
does, and what arguments does this expect by using o:dfath
.
How should I call this script and with what options?
Another thing that called my attention was the commented line (HERE
) . I commented it and now I can set use_data_calib
to true or false. However in the original code I am reading the line was not commented.
Doesn't that line defeat the purpose of the argument d
? Because with that line, use_data_calib
is always false...