gpt4 book ai didi

linux - 如何在 shell 脚本中编写用户定义的选项?

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:57:55 39 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
Using getopts in bash shell script to get long and short command line options

这是我写的代码

#! /bin/bash

getopts master $1

while getopts ":master" opt; do
case $opt in
master)
echo "-master was triggered! $1 was entered" >&2
;;
\?)
echo "Invalid option: -$OPTARG" >&2
;;
esac
done

这是我得到的输出-

]$ ./test123.sh -master 123
./test123.sh: line 3: getopts: `-master': not a valid identifier

如何定义用户定义的选项?

39 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com