简体   繁体   English

如何在 linux 中创建 shell 命令,如下所示:hh.sh filename -e -c?

[英]How can I create shell command in linux like this: hh.sh filename -e -c?

The options are following the filename rather than hh.sh.选项跟随文件名而不是 hh.sh。 And the following code does not work.并且以下代码不起作用。

while getopts ":ec" opt; do
  case $opt in
    e)
      eflag=1
      ;;
    c)
      cflag=1
      ;;
  esac
done
shift $(($OPTIND - 1))

what about something like this.这样的事情怎么样。

filename=$1
shift
while getopts ":ec" opt; do
  case $opt in
    e)
      eflag=1
      ;;
    c)
      cflag=1
      ;;
  esac
done
shift $(($OPTIND - 1))

echo $filename
echo $eflag
echo $cflag

grab the filename, then shift and run getopts?获取文件名,然后移动并运行 getopts?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我如何在Linux中使用Shell创建名称如number-number的束文件夹 - how can i create bunch folder with name like number-number using shell in linux 为什么 Linux shell 中带大括号的 `{cat,filename}` Group 命令可以工作? - Why the `{cat,filename}` Group command with braces in Linux shell can work? 如何在Linux中的文件名末尾创建带有&amp;符号的文件? - How can i create a file with & sign at the end of filename in linux? 如何使用 Linux 命令找到我的 shell 版本? - How can I find my shell version using a Linux command? 如何在Linux Shell中获取命令返回状态 - How can I obtain command returning status in linux shell 如何在Linux中创建Unicode文件名? - How do i create a unicode filename in linux? 如何在 Linux 中使用 Shell 或 Python 创建目录的哈希? - How can I create a hash of a directory in Linux in Shell or Python? Linux Shell脚本:如何创建将在后台运行的服务? - linux shell script: how can I create a service that will run in background? 命令“$(<div id="text_translate"><pre> kubectl create secret docker-registry $SECRET_NAME \ --dry-run=client \ --docker-server="$ECR_REGISTRY" \ --docker-username=AWS \ --docker-password="$(</token/ecr-token)" \ -o yaml</pre><p> 文件令牌/ecr-token 已到位但仍无法填充 --docker-password</p></div> - command "$(</token/ecr-token)" is not working in sh shell but working in bash , how we can make this command work in sh shell Linux / Ubuntu为sh文件创建可执行命令 - Linux/Ubuntu create executable command for sh file
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM