Bash字符串文字与变量失败的比较

时间:2018-07-31 16:44:18

标签: bash

我有以下简单的bash代码来测试字符串比较:

#!/bin/sh

BRANCH="master"

echo $ref

if [[ "$ref" = "refs/heads/$BRANCH" ]]
then
    echo "Matches"
else
    echo "Do not match"
fi

当我使用export ref=/refs/heads/master && . sample运行代码时,得到以下结果:

/refs/heads/master
Do not match

可能是什么原因引起的问题?

1 个答案:

答案 0 :(得分:3)

导致问题的原因是测试中缺少斜杠:/refs/heads/master不等于refs/heads/master

相关问题