shell中使用类似Python的参数处理

params=$*
for param in ${params}
do
    name=$(echo $param | cut -d "=" -f 1)
    value=$(echo $param | cut -d "=" -f 2)
    if [[ "$name" = "run_type" ]]; then
        run_type=$value
    elif [[ "$name" = "fix_start_date" ]]; then
        fix_start_date=$value
    elif [[ "$name" = "fix_end_date" ]]; then
        fix_end_date=$value
    elif [[ "$name" = "mysql_env" ]]; then
        mysql_env=$value
    elif [[ "$name" = "global_start_date" ]]; then
        global_start_date=$value
    fi
done

$*获取所有参数

for in 可以遍历默认以空格分割的字符串

用cut命令解析每个参数

猜你喜欢

转载自www.cnblogs.com/keensword/p/9359560.html