I have the following code:
while getopts ":p:t:n:" o; do
case "${o}" in
p)
p=${OPTARG}
numep=$p
mkdir $numep
;;
t)
t=${OPTARG}
tip=$t
if [ $tip == "c" ]; then
touch $numep/$numep.c
touch $numep/$numep.h
elif [ $tip == "c++" ]; then
touch $numep/$numep.cpp
touch $numep/$numep.h
fi
;;
n)
n=${OPTARG}
nrFis=$n
if [ $tip == "c" ]; then
for i in $(seq $n); do
touch $numep/src/$numep$i.c
touch $numep/inc/$numep$i.h
done
elif [ $tip == "c++" ]; then
for i in $(seq $n); do
touch $numep/src/$numep$i.cpp
touch $numep/inc/$numep$i.h
done
fi
;;
*)
err-help
;;
esac
done
err-help is a previously defined function that delivers instructions for a correct call.
A correct call of the script looks like this: ./script.sh -p project_name -t project_type -n source_files_number
What am I trying to do: create a directory with a specific number of source files for a c or a c++ project.
My questions here: How do I have to use the ${OPTARG} ? What exactly does the p=${OPTARG} thing? Will the p, t, n variables fill with the right content? How am I doing this right, please? :(