case语法.md

示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
casein
模式1)
command1
command2
command3
;;
模式2)
command1
command2
command3
;;
*)
command1
command2
command3
;;
esac

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
get_etcd() {
local option=$1
local target_dir=$2
local source_path_or_url=$3
local http_user=$4 # 仅 remote 时需要
local http_passwd=$5 # 仅 remote 时需要

case "$option" in
"local")
get_etcd_from_local "$source_path_or_url" "$target_dir"
;;
"remote")
get_etcd_from_remote "$target_dir" "$source_path_or_url" "$http_user" "$http_passwd"
;;
*)
echo "Invalid option: $option. Please choose 'local' or 'remote'."
exit 1
;;
esac
}


case语法.md
https://abrance.github.io/2024/03/27/domain/shell/case语法/
Author
xiaoy
Posted on
March 27, 2024
Licensed under