I am trying to work out how i can have multiple functions in one script and choose the function with an argument. what seems to be the issue is that if i choose a function the optarg does'nt seem to be run with the script. in this example I would run the script as such ~# ./script.sh -a -c wordlist.txt that to only run the first function with the wordlist of choice same as ~# ./script.sh -b -c wordlist.txt
#!/bin/bash
one()
{
for i in $(cat $wordlist); do
wget http://10.10.10.10/$i
}
two()
{
for i in (cat $wordlist); do
curl http://10.10.10.10/$i
}
while getopts "abc:" option; do
case "${option}" in
c) wordlist=${OPTARG} ;;
a) one;;
b) two;;
esac
done
dones../script.sh -a -c wordlist.txt, which causesgetoptsto call see-abefore-c, which causesoneto be called beforewordlistis asssigned. So either run./script.sh -c wordlist.txt -aor make sure to callone(ortwo) after thewhileloop.casestatement shouldn't actually do much, if any, actual work. Its job is to simply recognize and remember which options were seen. After the loop is the right time to perform any actions, once you have all the information available.