出于某种原因,第一个值总是被打印出来。我想不通这背后的原因。有什么想法吗?
#!/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/