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

标签 linux bash

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

#!/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/

相关文章:

python web.py 异步执行外部程序

linux - 在具有多个 Controller 的服务器中分配内存时,操作系统是否会选择内存 Controller ?如何?

perl - grep 变量并给出信息输出

string - 嵌套引号 bash

linux - 在bash中使用sed写入变量指定的行号

linux - 查找所有者或组不等于的地方

c++ - 检查文件描述符中可用缓冲区字符的数量

linux - 我在 SunOS 中的 shell 脚本有什么问题,在其他 Linux 版本上运行良好

linux - 在网络服务器上设置 Linux 机器

bash - 将一个子字符串替换为 shell 脚本中的另一个字符串