linux shell脚本 getopt使用
时间: 2024-01-03 08:21:48 浏览: 92
以下是关于Linux shell脚本中getopt的使用示例:
```shell
#!/bin/bash
echo "opt:" ${opt}
for opt; do
case $opt in
a) echo "a " ;;
b) echo "b " ;;
*) echo "other " ;;
esac
done
```
```shell
#!/bin/bash
while getopts "a:" opt; do
case $opt in
a) echo "this is -a the arg is ! $OPTARG" ;;
\?) echo "Invalid option: -$OPTARG" ;;
esac
done
```
阅读全文