I'm converting a script to utilize arguments, but it seems that my case statement is not evaluating all of the options I've provided. Below is the argument that I coded which is not working:
#!/bin/zsh
...
############################################################
# Delete Screenshots #
############################################################
Delete()
{
echo "\n*** DELETING SCREENSHOTS FROM ~/Pictures/Screenshots ***\n"
rm ~/Pictures/Screenshots/*.png
echo "Done!"
}
...
############################################################
############################################################
# Main program #
############################################################
############################################################
while getopts ":chapd:" option; do
case $option in
c) # Create Directories
CreateDir
exit;;
h) # Display Help
Help
exit;;
a) # Archive
Archive
exit;;
p) # Purge Archive
pArchive
exit;;
d) # Delete Screenshots
Delete
exit;;
\?) # Invalid option
echo "ERROR: Invalid option!"
exit;;
esac
done
When testing, all options appear to work (c,h,a,p) with the exception of d.
Can anyone help me understand why all of the options work except d? Is there a limitation of case that I'm not aware of? I tried searching for this answer, but I could not find something similar.
I run the program like this:
hsshots -d
. This option only fails without any error. I tried adding an echo "DEBUG"
just to see if there would be any output. I've even deleted the rm
command to see if only the echo
would prompt, but it does not. It seems to me that case
is just ignoring this last option.... OR getopts
is somehow ignoring this option as an option; I'm not sure.
Edited for simplicity as requested.