我如何以编程方式测试github是否有我的ssh密钥?

时间:2013-11-22 16:55:12

标签: bash github ssh

我确信我只是在用bash度过糟糕的一天。

我似乎无法在if语句中获取正确比较的退出代码。

我在这里做错了什么?

echo "Testing to see if GitHub knows who $USER is"
$(ssh -T "git@github.com")
echo $? #just for debugging                                                                                                                                                                                    
# Github exit code of 1 indicates that we can connect and that they do not support shell access.                                                                                                               
# exit code of 255 indicates a ssh error, in this case we assume an invalid key                                                                                                                                
if [ "$?" != "1" ]; then
    echo "Add your SSH key to your Github account"
    echo "* Log into GitHub.com with your Github username and password and visit https://github.com/settings/ssh"
    echo "* Click Add SSH Key"
    echo "* Paste in the following under 'Key':"
    echo "$(cat ~/.ssh/id_rsa.pub)"
    echo "Press Enter when done."
    read
fi

1 个答案:

答案 0 :(得分:2)

echo $?本身返回0并因此改变$?。取出你的调试语句。

你还需要$周围的报价吗?或者在你的条件中为1(它对我有用。)

相关问题