我什么时候不给选项提供参数,选项不起作用

我什么时候不给选项提供参数,选项不起作用

示例代码:

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

问题:

./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

我应该怎么做才能让它运行?

相关内容