gpt4 book ai didi

linux - bash if elif 语句总是打印第一个值

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:51:13 27 4
gpt4 key购买 nike

出于某种原因,第一个值总是被打印出来。我想不通这背后的原因。有什么想法吗?

#!/bin/bash
config="update_release"
if [[ "$config"=="update" ]]; then
schema_list="main_schemas"
elif [[ "$config"=="update_release" ]] ; then
schema_list="release_schemas"
elif [[ "$config"=="update_maintenance" ]]; then
schema_list="maintenance_schemas"
fi
echo $schema_list

我尝试了很多东西,包括 single =, single [] 但似乎什么都不管用。

最佳答案

您需要在条件中添加空格:

#!/bin/bash
config="update_release"
if [ "$config" == "update" ]; then
schema_list="main_schemas"
elif [ "$config" == "update_release" ] ; then
schema_list="release_schemas"
elif [ "$config" == "update_maintenance" ]; then
schema_list="maintenance_schemas"
fi
echo $schema_list

关于linux - bash if elif 语句总是打印第一个值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40278365/

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