Shell教程

Shell getopts选项

Shell Scripting getopts 选项

在 shell 脚本中使用 getopts 选项来解析传递给它们的参数。在命令行上传递参数时,getopts 会解析这些参数而不是命令行。
选项以连字符 (-) 开头,后跟字母。例如-a、-b、-c、-d等
不带参数的示例1:
Linux Shell Scripting Get script options with getopts 1
看上面的快照,我们创建了三个选项-a、-b和-c .任何选项都不需要参数。
Linux Shell Scripting Get script options with getopts 2
看上面的快照,这是上面脚本的示例输出。
带参数的示例 2:
Linux Shell Scripting Get script options with getopts 3
看上面的快照,选项b需要参数。
Linux Shell Scripting Get script options with getopts 4
看在上面的快照中,这是上面脚本的示例输出。
昵称: 邮箱:
Copyright © 2022 立地货 All Rights Reserved.
备案号:京ICP备14037608号-4