bash脚本编程操作员意外 [英] Bash scripting unexpected operator

查看:103
本文介绍了bash脚本编程操作员意外的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写的git的钩子脚本,并有麻烦如果语句,而

I'm writing script for git hook and have trouble with if statement inside while.

文件:

#!/bin/sh
while read oldrev newref ref
do
    branch=$(git rev-parse --symbolic --abbrev-ref $ref)

    if [ "a"  == "a" ]
    then
        echo "Condition work"
    fi

    echo "$branch"
done

错误:

hooks/post-receive: 6: [: a: unexpected operator

我会尝试使用变量,双引号,但如果不起作用。是什么样的错误,在这里?

I'll try with variables, double quotes but if doesn't work. What kind of error is here?

感谢

推荐答案

如果[一个==是] 如果[一个=一个]

庆典接受 == 而不是 = ,但你的 / bin / sh的可能不是bash的。

bash accepts == instead of =, but your /bin/sh probably isn't bash.

因此​​,无论修改 == = 或你的家当为#! /斌/庆典

So either change the == to =, or your shebang to #!/bin/bash

这篇关于bash脚本编程操作员意外的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆