使用getopts.sh Shell 脚本

Shell 片段 · codes/shell/输入和输出/使用getopts.sh · 14 行

源码

#!/usr/bin/env bash

# simple demonstration of the getopts command

while getopts :ab:c opt
do
	case "$opt" in
		a) echo "Found the -a option" ;;
		b) echo "Found the -b option, with value $OPTARG" ;;
		c) echo "Found the -c option" ;;
		*) echo "Unknown option:$opt" ;;
	esac
done

查看上游源码 ↗

内容与示例整理自 dunwu/linux-tutorial,遵循 CC BY-SA 4.0;本站保留原作者署名与许可,命令仅供学习,执行前请核对目标环境。