example code:
function purge() {
delete_dir;
case $purge_arg in
--static)
delete_static_dir;
;;
esac
}
while getopts ":nrp:h" opt; do
case ${opt} in
h ) guide;
;;
n ) new_address;
;;
r ) tor_server;
;;
p )
purge_arg=${OPTARG}
purge
;;
esac
done
problem:
./script.sh -p --static #it's work
deleting dir;
deleting static dir.
./script.sh -p #It should run the delete dir command but it doesn't work
what should i do to make it run?
purge
before settingpurge_arg
(on whichpurge
depends) – Andy Dalton Jun 14 '20 at 03:12-p
takes an argument and allow-p
to not take an argument, if you usegetopts
. – Kusalananda Jun 14 '20 at 07:51